Method: Ariel::Learner#add_new_landmarks
- Defined in:
- lib/ariel/learner.rb
#add_new_landmarks(landmark, index) ⇒ Object
Implements topology refinements - new landmarks are added to the current rule.
-
Takes a landmark and its index in the current rule.
-
Applies the rule consisting of all landmarks up to and including the current landmark to find where it matches.
-
Only tokens between the label_index and the position at which the partial rule matches are considered.
-
Tokens before the rule match location will have no effect, as adding new landmarks before or after the current landmark will not make the rule match any earlier.
-
For every token in this slice of the TokenStream, a new potential rule is created by adding a new landmark consisting of that token. This is also done for each of that token’s matching wildcards.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/ariel/learner.rb', line 226 def add_new_landmarks(landmark, index) topology_refs=[] start_pos = current_rule.partial(0..index).closest_match(current_seed, :early) end_pos = current_seed.label_index #No point adding tokens that occur after the label_index current_seed.tokens[start_pos...end_pos].each do |token| r=current_rule.deep_clone r.landmarks.insert(index+1, [token.text]) topology_refs << r topology_refs.concat r.generalise_feature(index+1) end Log.debug "Topology refinements before uniq! #{topology_refs.size}" topology_refs.uniq! @candidates.concat topology_refs Log.debug "#{topology_refs.size} topology refinements generated" return topology_refs.size end |