Module: DataMapper::Semantic::ClassMethods

Defined in:
lib/dm-semantic/functions.rb

Instance Method Summary collapse

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


Parameters:

  • format (Symbol) (defaults to: :rdf)

    format of the ontology to which the URI points (:rdf, :turtle, or :json). Defaults to :rdf

Returns:

  • (String)

    the OWL ontology in the requested format.

Author:

  • Pius Uzamere



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


Parameters:

  • format (Symbol)

    format of the OWL-RDF output (:xml, :turtle, or :json). Defaults to :turtle

Returns:

  • (String)

    the OWL ontology in the requested format.

Author:

  • Pius Uzamere



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_definitionGraph

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


Returns:

  • (Graph)

    graph of the OWL triples for the bare class.

Author:

  • Pius Uzamere



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


Returns:

  • (Graph)

    graph of the OWL triples for the property.

Author:

  • Pius Uzamere



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