Class: RDF::Statement
- Inherits:
-
Object
- Object
- RDF::Statement
- Defined in:
- lib/rdfs/rule.rb
Constant Summary collapse
- PLACEHOLDERS =
(p = [:aaa, :bbb, :ccc, :ddd, :uuu, :vvv, :xxx, :yyy, :zzz]) + p.collect {|pl| RDF::Literal.new(pl)} + p.collect {|pl| RDF::Node.new(pl)}
Instance Method Summary collapse
- #generality ⇒ Object
- #has_placeholder? ⇒ Boolean
- #specificity ⇒ Object
-
#with_substitutions(assignment_hash) ⇒ Object
TODO: consider moving these methods into the RDF gem instead of reopening RDF::Statement here.
Instance Method Details
#generality ⇒ Object
17 18 19 |
# File 'lib/rdfs/rule.rb', line 17 def generality to_hash.values.select {|k| PLACEHOLDERS.include? k}.size end |
#has_placeholder? ⇒ Boolean
21 22 23 |
# File 'lib/rdfs/rule.rb', line 21 def has_placeholder? to_hash.values.detect {|k| PLACEHOLDERS.include? k} end |
#specificity ⇒ Object
25 26 27 |
# File 'lib/rdfs/rule.rb', line 25 def specificity 3-generality end |
#with_substitutions(assignment_hash) ⇒ Object
TODO: consider moving these methods into the RDF gem instead of reopening RDF::Statement here
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rdfs/rule.rb', line 6 def with_substitutions(assignment_hash) return self unless assignment_hash statement_hash = to_hash [:subject, :object, :predicate].each { |place_in_statement| bound_variables, variable = assignment_hash.keys, statement_hash[place_in_statement] statement_hash[place_in_statement] = assignment_hash[variable] if bound_variables.collect(&:to_s).include?(variable.to_s) #TODO: fix node equality so I don't need to use to_s above } Statement.new(statement_hash) end |