class RoadForest::PathMatcher::Edge
Attributes
accepting_count[R]
max_multi[RW]
max_repeat[RW]
min_multi[RW]
min_repeat[RW]
predicate[RW]
rejecting_count[R]
Public Class Methods
edge_query_pattern(pattern_node)
click to toggle source
# File lib/roadforest/path-matcher.rb, line 113 def edge_query_pattern(pattern_node) path_direction = self.path_direction RDF::Query.new do pattern [ pattern_node, path_direction, :next ] pattern [ :next, Graph::Path.predicate, :predicate ] pattern [ :next, Graph::Path.minMulti, :min_multi ], :optional => true pattern [ :next, Graph::Path.maxMulti, :max_multi ], :optional => true pattern [ :next, Graph::Path.minRepeat, :min_repeat ], :optional => true pattern [ :next, Graph::Path.maxRepeat, :max_repeat ], :optional => true pattern [ :next, Graph::Path.is, :exact_value ], :optional => true pattern [ :next, Graph::Path.after, :after ], :optional => true pattern [ :next, Graph::Path.before, :before ], :optional => true pattern [ :next, Graph::Path.order, :order ], :optional => true pattern [ :next, Graph::Path.type, :type ], :optional => true end end
find_child_edges(node)
click to toggle source
# File lib/roadforest/path-matcher.rb, line 105 def find_child_edges(node) node.pattern.query(edge_query_pattern(node.pattern_step)).map do |solution| new do |edge| edge.from(node, solution) end end end
Public Instance Methods
accepting?()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 219 def accepting? return false if children.nil? resolved? and not rejecting? end
available_count()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 224 def available_count child_nodes.length - rejecting_count end
build_children()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 228 def build_children Node.find_child_nodes(self) end
excluded?()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 176 def excluded? step_count >= max_repeat end
from(node, solution)
click to toggle source
# File lib/roadforest/path-matcher.rb, line 131 def from(node, solution) self.parent = node self.pattern = node.pattern self.graph = node.graph self.stem = node.stem.merge(node.statement => true) self.repeats = node.repeats self.graph_term = node.graph_term self.predicate = solution[:predicate] unless solution[:min_multi].nil? and solution[:max_multi].nil? self.min_multi = solution[:min_multi].nil? ? 0 : solution[:min_multi].object self.max_multi = solution[:max_multi].nil? ? nil : solution[:max_multi].object end unless solution[:min_repeat].nil? and solution[:max_repeat].nil? self.min_repeat = solution[:max_repeat].nil? ? 0 : solution[:min_repeat].object self.max_repeat = solution[:max_repeat].nil? ? nil : solution[:max_repeat].object end self.exact_value = solution[:exact_value] self.pattern_step = solution[:next] self.after = solution[:after] self.before = solution[:before] self.order = solution[:order] self.type = solution[:type] end
notify_resolved(child)
click to toggle source
# File lib/roadforest/path-matcher.rb, line 193 def notify_resolved(child) @accepting_count += 1 if child.accepting? @rejecting_count += 1 if child.rejecting? end
rejecting?()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 212 def rejecting? return false if children.nil? return false if excluded? return false if satisfied? (not max_multi.nil? and accepting_count > max_multi) or available_count < min_multi end
reset()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 184 def reset @accepting_count = 0 @rejecting_count = 0 @min_multi = 1 @max_multi = 1 @min_repeat = 1 @max_repeat = 1 end
resolved?()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 198 def resolved? return false if children.nil? @resolved ||= begin if rejecting? true else not children.any? do |node| not node.resolved? end end end end
satisfied?()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 180 def satisfied? step_count >= min_repeat end
step_count()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 172 def step_count repeats.fetch(pattern_step, 0) end
to_s()
click to toggle source
# File lib/roadforest/path-matcher.rb, line 160 def to_s state = case when !resolved? "?" when accepting? "Acpt" when rejecting? "Rjct" end "<#{self.class.name.sub(/.*::/,'')} #{predicate}*M:#{min_multi}(<?#{available_count rescue "-"})-(#{accepting_count rescue "-"}<?)#{max_multi} R:#{min_repeat}-#{max_repeat}:#{step_count} #{state} >" end