Created
August 17, 2012 09:52
-
-
Save nanki/3377562 to your computer and use it in GitHub Desktop.
generate .gml from space-separated-values.
This file contains 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 | |
i = 0 | |
hash = {} | |
edges = '' | |
ARGF.each do |line| | |
id1, id2s = line.strip.split /\s/ | |
id2s.split(",").each do |id2| | |
hash[id1] ||= i += 1 | |
hash[id2] ||= i += 1 | |
next if id1 == id2 | |
edges.concat <<EOF | |
edge [ | |
source #{hash[id1]} | |
target #{hash[id2]} | |
] | |
EOF | |
end | |
end | |
puts "graph [" | |
hash.keys.each do |node| | |
print <<EOF | |
node [ | |
id #{hash[node]} | |
label "#{node}" | |
] | |
EOF | |
end | |
print edges | |
puts "]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment