Class: RDF::Microdata::Expansion::Rule
- Inherits:
-
Object
- Object
- RDF::Microdata::Expansion::Rule
- Includes:
- Util::Logger
- Defined in:
- lib/rdf/microdata/expansion.rb
Overview
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
Instance Attribute Summary collapse
-
#antecedents ⇒ Array<RDF::Query::Pattern>
readonly
Patterns necessary to invoke this rule.
-
#consequents ⇒ Array<RDF::Query::Pattern>
readonly
Result of this rule.
-
#name ⇒ String
readonly
Name of this rule.
Instance Method Summary collapse
- #antecedent(subject, prediate, object) ⇒ Object
- #consequent(subject, prediate, object) ⇒ Object
-
#execute(queryable) {|statement| ... } ⇒ Object
Execute the rule against queryable, yielding each consequent with bindings.
-
#initialize(name, **options, &block) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(name, **options, &block) ⇒ Rule
Returns a new instance of Rule.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rdf/microdata/expansion.rb', line 74 def initialize(name, **, &block) @antecedents = [] @consequents = [] @options = .dup @name = name if block_given? case block.arity when 1 then block.call(self) else instance_eval(&block) end end end |
Instance Attribute Details
#antecedents ⇒ Array<RDF::Query::Pattern> (readonly)
Returns patterns necessary to invoke this rule.
53 54 55 |
# File 'lib/rdf/microdata/expansion.rb', line 53 def antecedents @antecedents end |
#consequents ⇒ Array<RDF::Query::Pattern> (readonly)
Returns result of this rule.
57 58 59 |
# File 'lib/rdf/microdata/expansion.rb', line 57 def consequents @consequents end |
#name ⇒ String (readonly)
Returns Name of this rule.
61 62 63 |
# File 'lib/rdf/microdata/expansion.rb', line 61 def name @name end |
Instance Method Details
#antecedent(subject, prediate, object) ⇒ Object
88 89 90 |
# File 'lib/rdf/microdata/expansion.rb', line 88 def antecedent(subject, prediate, object) antecedents << RDF::Query::Pattern.new(subject, prediate, object) end |
#consequent(subject, prediate, object) ⇒ Object
92 93 94 |
# File 'lib/rdf/microdata/expansion.rb', line 92 def consequent(subject, prediate, object) consequents << RDF::Query::Pattern.new(subject, prediate, object) end |
#execute(queryable) {|statement| ... } ⇒ Object
Execute the rule against queryable, yielding each consequent with bindings
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rdf/microdata/expansion.rb', line 102 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 |