Skip to content

Instantly share code, notes, and snippets.

@balhoff
Created February 13, 2011 19:37
Show Gist options
  • Save balhoff/824997 to your computer and use it in GitHub Desktop.
Save balhoff/824997 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rdf'
require 'rdf/rdfxml'
graph = RDF::Graph.new
jaw = RDF::URI.new("http://example.org/jaw")
graph << RDF::Statement.new(jaw, RDF.type, RDF::OWL.Class)
bone = RDF::URI.new("http://example.org/bone")
graph << RDF::Statement.new(bone, RDF.type, RDF::OWL.Class)
jawbone = RDF::URI.new("http://example.org/jawbone")
graph << RDF::Statement.new(jawbone, RDF.type, RDF::OWL.Class)
part_of = RDF::URI.new("http://example.org/part_of")
graph << RDF::Statement.new(part_of, RDF.type, RDF::OWL.ObjectProperty)
part_of_jaw = RDF::Node.new
graph << RDF::Statement.new(part_of_jaw, RDF.type, RDF::OWL.Class)
graph << RDF::Statement.new(part_of_jaw, RDF.type, RDF::OWL.Restriction)
graph << RDF::Statement.new(part_of_jaw, RDF::OWL.onProperty, part_of)
graph << RDF::Statement.new(part_of_jaw, RDF::OWL.someValuesFrom, jaw)
bone_and_part_of_jaw = RDF::Node.new
graph << RDF::Statement.new(bone_and_part_of_jaw, RDF.type, RDF::OWL.Class)
bone_and_part_of_jaw_members = RDF::List[bone, part_of_jaw]
graph.insert *(bone_and_part_of_jaw_members.statements.to_a)
graph << RDF::Statement.new(bone_and_part_of_jaw, RDF::OWL.intersectionOf, bone_and_part_of_jaw_members.subject)
graph << RDF::Statement.new(jawbone, RDF::OWL.equivalentClass, bone_and_part_of_jaw)
#rdf = RDF::Writer.for(:ntriples).buffer {|writer| writer << graph }
rdf = RDF::RDFXML::Writer.buffer {|writer| writer << graph }
puts rdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment