Class: RDF::RDFa::Expansion::Rule
- Inherits:
-
Object
- Object
- RDF::RDFa::Expansion::Rule
- Defined in:
- 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)
- - (Object) antecedents readonly
- - (Object) consequents readonly
- - (Object) name readonly
Instance Method Summary (collapse)
- - (Object) antecedent(subject, prediate, object, context = nil)
- - (Object) consequent(subject, prediate, object, context = nil)
-
- (Object) execute(queryable) {|statement| ... }
Execute the rule against queryable, yielding each consequent with bindings.
-
- (Rule) initialize(name, &block)
constructor
A new instance of Rule.
Constructor Details
- (Rule) initialize(name, &block)
A new instance of Rule
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rdf/rdfa/expansion.rb', line 112 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
- (Object) antecedents (readonly)
93 94 95 |
# File 'lib/rdf/rdfa/expansion.rb', line 93 def antecedents @antecedents end |
- (Object) consequents (readonly)
96 97 98 |
# File 'lib/rdf/rdfa/expansion.rb', line 96 def consequents @consequents end |
- (Object) name (readonly)
99 100 101 |
# File 'lib/rdf/rdfa/expansion.rb', line 99 def name @name end |
Instance Method Details
- (Object) antecedent(subject, prediate, object, context = nil)
125 126 127 |
# File 'lib/rdf/rdfa/expansion.rb', line 125 def antecedent(subject, prediate, object, context = nil) antecedents << RDF::Query::Pattern.new(subject, prediate, object, :context => context) end |
- (Object) consequent(subject, prediate, object, context = nil)
129 130 131 |
# File 'lib/rdf/rdfa/expansion.rb', line 129 def consequent(subject, prediate, object, context = nil) consequents << RDF::Query::Pattern.new(subject, prediate, object, :context => context) end |
- (Object) execute(queryable) {|statement| ... }
Execute the rule against queryable, yielding each consequent with bindings
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/rdf/rdfa/expansion.rb', line 139 def execute(queryable) RDF::Query.new(antecedents).execute(queryable).each do |solution| nodes = {} consequents.each do |consequent| terms = {} [:subject, :predicate, :object, :context].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 |