class RDF::RDFa::Expansion::Rule
An entailment rule
Takes a list of antecedent patterns used to find solutions against a queryable object. Yields each consequent with bindings from the solution
Attributes
antecedents[R]
@!attribute [r] antecedents @return [Array<RDF::Query::Pattern>]
consequents[R]
@!attribute [r] consequents @return [Array<RDF::Query::Pattern>]
deletions[R]
@!attribute [r] deletions @return [Array<RDF::Query::Pattern>]
name[R]
@!attribute [r] name @return [String]
Public Class Methods
new(name, &block)
click to toggle source
@example
r = Rule.new("scm-spo") do antecedent :p1, RDF::RDFS.subPropertyOf, :p2 antecedent :p2, RDF::RDFS.subPropertyOf, :p3 consequent :p1, RDF::RDFS.subPropertyOf, :p3, "t-box" end r.execute(queryable) {|statement| puts statement.inspect}
@param [String] name
# File lib/rdf/rdfa/expansion.rb, line 91 def initialize(name, &block) @antecedents = [] @consequents = [] @name = name if block_given? case block.arity when 1 then block.call(self) else instance_eval(&block) end end end
Public Instance Methods
antecedent(subject, prediate, object)
click to toggle source
# File lib/rdf/rdfa/expansion.rb, line 104 def antecedent(subject, prediate, object) antecedents << RDF::Query::Pattern.new(subject, prediate, object) end
consequent(subject, prediate, object)
click to toggle source
# File lib/rdf/rdfa/expansion.rb, line 108 def consequent(subject, prediate, object) consequents << RDF::Query::Pattern.new(subject, prediate, object) end
execute(queryable) { |from| ... }
click to toggle source
Execute the rule against queryable, yielding each consequent with bindings
@param [RDF::Queryable] queryable @yield [statement] @yieldparam [RDF::Statement] statement
# File lib/rdf/rdfa/expansion.rb, line 118 def execute(queryable) RDF::Query.new(antecedents).execute(queryable).each do |solution| nodes = {} consequents.each do |consequent| terms = {} [:subject, :predicate, :object].each do |r| terms[r] = case o = consequent.send(r) when RDF::Node then nodes[o] ||= RDF::Node.new when RDF::Query::Variable then solution[o] else o end end yield RDF::Statement.from(terms) end end end