Module: DataMapper::Semantic::ClassMethods
- Defined in:
- lib/dm-semantic/functions.rb
Instance Method Summary collapse
-
#ontologies(format = :rdf) ⇒ String
Returns a hash of the ontologies to which the model is mapped, along with their authoritative URIs.
-
#to_owl(*args) ⇒ String
Export the entire class definition as an OWL ontology.
-
#triples_for_class_definition ⇒ Graph
Create the basic OWL triples for the class, without the properties.
-
#triples_for_property(property) ⇒ Graph
Create the OWL triples for a DataMapper property.
Instance Method Details
#ontologies(format = :rdf) ⇒ String
Returns a hash of the ontologies to which the model is mapped, along with their authoritative URIs.
Example
Person.ontologies # returns {:foaf => "http://xmlns.com/foaf/spec/"}
Person.ontologies(:rdf) # returns {:foaf => "http://xmlns.com/foaf/spec/index.rdf"}
Returns
38 39 40 |
# File 'lib/dm-semantic/functions.rb', line 38 def ontologies(format = :rdf) raise "Not Yet Implemented" end |
#to_owl(*args) ⇒ String
Export the entire class definition as an OWL ontology.
Example
Person.to_owl # returns string representation of the OWL ontology in Turtle.
Person.to_owl(:json) # returns string representation of the OWL ontology in RDF-JSON.
Rules for creating the ontology
The class itself will be represented by a b-node.
Returns
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dm-semantic/functions.rb', line 60 def to_owl(*args) g = Graph.new owl = Namespace.new('http://www.w3.org/2002/07/owl', 'owl', true) foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf") rdf = Namespace.new("http://www.w3.org/1999/02/22-rdf-syntax-ns", "rdf", true) rdfs = Namespace.new("http://www.w3.org/2000/01/rdf-schema", 'rdfs', true) xsd = Namespace.new('http://www.w3.org/2001/XMLSchema', 'xsd', true) for property in properties g << Triple.new(BNode.new('john'), foaf.knows, BNode.new('jane')) end return g end |
#triples_for_class_definition ⇒ Graph
Create the basic OWL triples for the class, without the properties.
Example
Person.triple_for_class_definition # returns a graph of the triples representing the bare class in OWL.
Rules for creating the ontology
The class itself will be represented by a b-node.
Returns
90 91 92 93 94 95 96 |
# File 'lib/dm-semantic/functions.rb', line 90 def triples_for_class_definition declare_namespaces g = Graph.new b = BNode.new(self.name) g << Triple.new(b, URIRef.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), URIRef.new('http://www.w3.org/2002/07/owl#Class')) return g end |
#triples_for_property(property) ⇒ Graph
Create the OWL triples for a DataMapper property.
Example
Person.triples_for_property(Person.properties[:id]) # returns a graph of the triples representing the id property on Person in OWL.
Returns
112 113 114 115 116 117 118 |
# File 'lib/dm-semantic/functions.rb', line 112 def triples_for_property(property) g = Graph.new b = BNode.new(property.field) t = Triple.new(b, URIRef.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), URIRef.new('http://www.w3.org/2002/07/owl#DatatypeProperty')) g << t return g end |