Skip to content

Instantly share code, notes, and snippets.

@danbri
Created June 7, 2011 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbri/1011898 to your computer and use it in GitHub Desktop.
Save danbri/1011898 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def out(str)
str = str.join(' ; ')
# return str.gsub(/http:\/\/schema\.org\//,"")
end
base = 'http://schema.org/'
ix = {}
f = File.read('_types.txt').each do |line|
c, sc = line.chomp!.split(/\t/,2)
c.gsub!(/</,'')
sc.gsub!(/</,'')
c.gsub!(/>/,'')
sc.gsub!(/>/,'')
# puts "CLASS: #{c} SUPERCLASS: #{sc}"
if ( (ix[sc]) != nil)
# puts "Not nil."
# puts "Array was: ",out(ix[sc])
ix[sc].push(c)
# puts "Array is now: ",out(ix[sc])
else
# puts "Nil."
ix[sc]= [ c ]
end
end
def clean(str)
return str.gsub(/http:\/\/schema\.org\//,"")
end
root = base+'Thing'
o = {}
#print "\nTest: looking for events...\n\n"
#print ix['http://schema.org/Event'].join(" // ")
i = 1
def dig(ix,u,i)
i = i+1
print " "[0..i]
node = {}
subs = ix[u]
if (subs)
print "#{clean(u)}: { \n"
subs.each do |x|
dig(ix,x,i)
end
print " "[0..i]+"}\n"
else
print " "[0..i]+"#{clean(u)}: 1 , \n"
end
end
dig(ix,root,i)
#ix.each do |x,y|
# puts "x: #{x} -> y: #{y}"
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment