#!/usr/bin/env ruby # RDF query (in memory version), Dan Brickley require 'squish' require 'basicrdf' #vdl = Loader.rdf2graph 'rdf_vdl.xml', 'http://www.w3.org/2000/01/rdf-schema#' #`rdfdump -o ntriples file:rdf_vdl.xml > rdf_vdl.nt` def shortname (uri) uri = uri.to_s uri.gsub!('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf:') uri.gsub!(/http:\/\/www.w3.org\/2000\/01\/rdf-schema#/, 'rdfs:') return uri end vdl = Loader.ntfile2graph 'rdf_vdl.nt' FOAF = vdl.reg_xmlns 'http://xmlns.com/foaf/0.1/', 'foaf' DC = vdl.reg_xmlns 'http://purl.org/dc/elements/1.1/', 'dc' RDF = vdl.reg_xmlns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#','rdf' VDL = vdl.reg_xmlns 'http://www.w3.org/2000/01/rdf-schema#','vdl' #puts "RDF Vocab

RDF Vocabulary

\n" s1=Statement.new (nil, RDF+'type', VDL+'Class') s2=Statement.new (nil, RDF+'type', RDF+'Property') classes = vdl.ask s1 props = vdl.ask s2 puts "\n" classes.subjects.each do |classuri| c = Node.getResource classuri, vdl # puts "C is #{c.inspect} \n" name = shortname(classuri) #+" label="+c.vdl_label.to_s puts "\n \n" puts " \n" end puts "\n
Class namecomment
#{name}#{c.vdl_comment}
\n\n" puts "\n" # todo: are there any multi-valued domain or range declarations? props.subjects.each do |propuri| p = Node.getResource propuri, vdl r = p.vdl_range rt = r.to_s if (r.to_s == "") rt = 'not specified' end d= p.vdl_domain dt = d.to_s if (d.to_s == "") dt = 'not specified' end rt = shortname rt dt = shortname dt name = shortname (propuri) # + " label="+p.vdl_label.to_s puts "\n \n" puts " \n" end puts "\n
Property namecommentdomainrange
#{name}#{p.vdl_comment.to_s}#{dt}#{rt}
\n\n"