Class: RoadForest::PathMatcher::Edge
- Defined in:
- lib/roadforest/path-matcher.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#accepting_count ⇒ Object
readonly
Returns the value of attribute accepting_count.
-
#max_multi ⇒ Object
Returns the value of attribute max_multi.
-
#max_repeat ⇒ Object
Returns the value of attribute max_repeat.
-
#min_multi ⇒ Object
Returns the value of attribute min_multi.
-
#min_repeat ⇒ Object
Returns the value of attribute min_repeat.
-
#predicate ⇒ Object
Returns the value of attribute predicate.
-
#rejecting_count ⇒ Object
readonly
Returns the value of attribute rejecting_count.
Attributes inherited from MatchStep
#after, #before, #children, #exact_value, #graph, #graph_term, #order, #parent, #pattern, #pattern_step, #repeats, #satified, #stem, #type
Class Method Summary collapse
Instance Method Summary collapse
- #accepting? ⇒ Boolean
- #available_count ⇒ Object
- #build_children ⇒ Object
- #excluded? ⇒ Boolean
- #from(node, solution) ⇒ Object
- #notify_resolved(child) ⇒ Object
- #rejecting? ⇒ Boolean
- #reset ⇒ Object
- #resolved? ⇒ Boolean
- #satisfied? ⇒ Boolean
- #step_count ⇒ Object
- #to_s ⇒ Object
Methods inherited from MatchStep
#immediate_match, #initialize, #matched_statements, #open, #pretty_print_instance_variables
Constructor Details
This class inherits a constructor from RoadForest::PathMatcher::MatchStep
Instance Attribute Details
#accepting_count ⇒ Object (readonly)
Returns the value of attribute accepting_count.
99 100 101 |
# File 'lib/roadforest/path-matcher.rb', line 99 def accepting_count @accepting_count end |
#max_multi ⇒ Object
Returns the value of attribute max_multi.
100 101 102 |
# File 'lib/roadforest/path-matcher.rb', line 100 def max_multi @max_multi end |
#max_repeat ⇒ Object
Returns the value of attribute max_repeat.
100 101 102 |
# File 'lib/roadforest/path-matcher.rb', line 100 def max_repeat @max_repeat end |
#min_multi ⇒ Object
Returns the value of attribute min_multi.
100 101 102 |
# File 'lib/roadforest/path-matcher.rb', line 100 def min_multi @min_multi end |
#min_repeat ⇒ Object
Returns the value of attribute min_repeat.
100 101 102 |
# File 'lib/roadforest/path-matcher.rb', line 100 def min_repeat @min_repeat end |
#predicate ⇒ Object
Returns the value of attribute predicate.
97 98 99 |
# File 'lib/roadforest/path-matcher.rb', line 97 def predicate @predicate end |
#rejecting_count ⇒ Object (readonly)
Returns the value of attribute rejecting_count.
99 100 101 |
# File 'lib/roadforest/path-matcher.rb', line 99 def rejecting_count @rejecting_count end |
Class Method Details
.edge_query_pattern(pattern_node) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# 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) ⇒ Object
105 106 107 108 109 110 111 |
# 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 |
Instance Method Details
#accepting? ⇒ Boolean
219 220 221 222 |
# File 'lib/roadforest/path-matcher.rb', line 219 def accepting? return false if children.nil? resolved? and not rejecting? end |
#available_count ⇒ Object
224 225 226 |
# File 'lib/roadforest/path-matcher.rb', line 224 def available_count child_nodes.length - rejecting_count end |
#build_children ⇒ Object
228 229 230 |
# File 'lib/roadforest/path-matcher.rb', line 228 def build_children Node.find_child_nodes(self) end |
#excluded? ⇒ Boolean
176 177 178 |
# File 'lib/roadforest/path-matcher.rb', line 176 def excluded? step_count >= max_repeat end |
#from(node, solution) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# 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) ⇒ Object
193 194 195 196 |
# 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? ⇒ Boolean
212 213 214 215 216 217 |
# 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 ⇒ Object
184 185 186 187 188 189 190 191 |
# 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? ⇒ Boolean
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# 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? ⇒ Boolean
180 181 182 |
# File 'lib/roadforest/path-matcher.rb', line 180 def satisfied? step_count >= min_repeat end |
#step_count ⇒ Object
172 173 174 |
# File 'lib/roadforest/path-matcher.rb', line 172 def step_count repeats.fetch(pattern_step, 0) end |
#to_s ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# 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 |