Class: RDF::RDFa::Expansion::Rule
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/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
- #consequents ⇒ Array<RDF::Query::Pattern> readonly
- #deletions ⇒ Array<RDF::Query::Pattern> readonly
- #name ⇒ String readonly
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, &block) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(name, &block) ⇒ Rule
Returns a new instance of Rule.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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 |
Instance Attribute Details
#antecedents ⇒ Array<RDF::Query::Pattern> (readonly)
66 67 68 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/expansion.rb', line 66 def antecedents @antecedents end |
#consequents ⇒ Array<RDF::Query::Pattern> (readonly)
70 71 72 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/expansion.rb', line 70 def consequents @consequents end |
#deletions ⇒ Array<RDF::Query::Pattern> (readonly)
74 75 76 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/expansion.rb', line 74 def deletions @deletions end |
#name ⇒ String (readonly)
78 79 80 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/expansion.rb', line 78 def name @name end |
Instance Method Details
#antecedent(subject, prediate, object) ⇒ Object
104 105 106 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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) ⇒ Object
108 109 110 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/expansion.rb', line 108 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
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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 |