Created
May 27, 2011 23:31
-
-
Save basicxman/996399 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Extended Mind | |
| # Now I want to graph the data, luckily we can just use the YAML cache as a data source. | |
| require 'yaml' | |
| require 'ap' | |
| class Graph | |
| attr_accessor :graph | |
| def initialize | |
| data = {} | |
| file_data = YAML.load_file("./mind_cur.cache") | |
| file_data.each do |parent, child| | |
| data[unwikify(parent)] = unwikify(child) | |
| end | |
| @global_store = {} | |
| data.each do |parent, child| | |
| @global_store[child] ||= [] | |
| @global_store[child] << parent | |
| end | |
| ap @global_store | |
| @graph = {} | |
| @graph["Philosophy"] = resolve("Philosophy") | |
| end | |
| def resolve(root) | |
| puts "Resolving #{root}" | |
| temp = {} | |
| @global_store[root].each do |key| | |
| if @global_store[key].nil? | |
| temp[key] = :done | |
| else | |
| temp[key] = resolve(key) | |
| end | |
| end | |
| temp | |
| end | |
| def unwikify(text) | |
| temp = text.dup | |
| temp.gsub! "http://wikipedia.org", "" | |
| temp.gsub! "/wiki/", "" | |
| temp | |
| end | |
| end | |
| g = Graph.new | |
| ap g.graph |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bah! Mah stack, it's not big enough.