Module: RDF::RDFa::Expansion

Included in:
Reader
Defined in:
lib/rdf/rdfa/expansion.rb,
lib/rdf/rdfa/expansion/v.rb,
lib/rdf/rdfa/expansion/gr.rb,
lib/rdf/rdfa/expansion/cc.rb,
lib/rdf/rdfa/expansion/dc.rb,
lib/rdf/rdfa/expansion/foaf.rb,
lib/rdf/rdfa/expansion/doap.rb,
lib/rdf/rdfa/expansion/sioc.rb,
lib/rdf/rdfa/expansion/skos.rb,
lib/rdf/rdfa/expansion/skosxl.rb,
lib/rdf/rdfa/expansion/schema.rb

Overview

The Expansion module performs a subset of OWL entailment rules on the base class, which implementes RDF::Readable.

Defined Under Namespace

Classes: Rule

Constant Summary

COOKED_VOCAB_STATEMENTS =

Pre-processed vocabularies used to simplify loading of common vocabularies

[]

Instance Method Summary (collapse)

Instance Method Details

- (RDF::Graph) expand

Perform vocabulary expansion on the resulting default graph.

Vocabulary expansion relies on a sub-set of OWL [OWL2-PROFILES] entailment to add
triples to the default graph based on rules and property/class relationships
described in referenced vocabularies.

For all objects that are the target of an rdfa:usesVocabulary property, load the IRI into a repository.

Subsequently, perform OWL expansion using rules prp-spo1, prp-eqp1, prp-eqp2, cax-sco, cax-eqc1, and cax-eqc2 placing resulting triples into the default graph. Iterate on this step until no more triples are added.

Examples:

scm-spo
{pq rdfs:subPropertyOf pw . pw rdfs:subPropertyOf p3} => {p1 rdfs:subPropertyOf p3}

rdprp-spo1fs7
{p1 rdfs:subPropertyOf p2 . x p1 y} => {x p2 y}

cax-sco
{c1 rdfs:subClassOf c2 . x rdf:type c1} => {x rdf:type c2}

scm-sco
{c1 rdfs:subClassOf c2 . c2 rdfs:subClassOf c3} => {c1 rdfs:subClassOf c3}

Returns:

  • (RDF::Graph)

See Also:

  • PROFILES](http://www.w3.org/TR/2009/REC-owl2-profiles-20091027/#Reasoning_in_OWL_2_RL_and_RDF_Graphs_using_Rules)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rdf/rdfa/expansion.rb', line 39

def expand
  repo = RDF::Repository.new
  repo << self  # Add default graph
  
  count = repo.count
  add_debug("expand") {"Loaded #{repo.size} triples into default graph"}
  
  # Vocabularies managed in vocab_repo, and copied to repo for processing.
  # This allows for persistent storage of vocabularies
  @@vocab_repo = @options[:vocab_repository] if @options.has_key?(:vocab_repository)
  @@vocab_repo ||= RDF::Repository.new.insert(*COOKED_VOCAB_STATEMENTS)
  
  vocabs = repo.query(:predicate => RDF::RDFA.usesVocabulary).to_a.map(&:object)
  vocabs.each do |vocab|
    begin
      unless @@vocab_repo.has_context?(vocab)
        add_debug("expand", "Load #{vocab}")
        @@vocab_repo.load(vocab, :context => vocab)
      end
    rescue Exception => e
      # XXX: update spec to indicate the error if the vocabulary fails to laod
      add_warning("expand", "Error loading vocabulary #{vocab}: #{e.message}", RDF::RDFA.UnresovedVocabulary)
    end
  end
  
  @@vocab_repo.each do |statement|
    if vocabs.include?(statement.context)
      repo << statement
    end
  end
  
  if repo.count == count
    add_debug("expand", "No vocabularies loaded")
  else
    repo = owl_entailment(repo)
  end

  # Return graph with default context
  graph = RDF::Graph.new
  repo.statements.each {|st| graph << st if st.context.nil?}
  graph
end

- (Object) rule(name, &block)



82
83
84
# File 'lib/rdf/rdfa/expansion.rb', line 82

def rule(name, &block)
  Rule.new(name, block)
end