Method: Ariel::Learner#lengthen_landmark
- Defined in:
- lib/ariel/learner.rb
#lengthen_landmark(landmark, index) ⇒ Object
Implements landmark refinements. Landmarks are lengthened to make them more specific.
-
Takes a landmark and its index in the current rule.
-
Applies the rule consisting of all previous landmarks in the current rule, so the landmark can be considered in the context of the point from which it shall be applied.
-
Every point at which the landmark matches after the cur_loc is considered.
-
Two extended landmarks are generated - a landmark that includes the token before the match, and a landmark that includes that token after the match.
-
Rules are generated incorporating these extended landmarks, including alternative landmark extensions that use relevant wildcards.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/ariel/learner.rb', line 187 def lengthen_landmark(landmark, index) current_seed.rewind #In case apply_rule isn't called as index=0 result = @current_rule.partial(0..(index-1)).closest_match current_seed if index > 0 #Don't care about already matched tokens return 0 unless result # Rule doesn't match, no point refining refined_rules=[] width = landmark.size while current_seed.skip_to(*landmark) #Probably should stop when cur_pos > label_index break if current_seed.cur_pos > current_seed.label_index match_start = (current_seed.cur_pos - 1) - width #pos of first matched token match_end = current_seed.cur_pos - 1 #pos of last matched token preceding_token = current_seed.tokens[match_start-1] trailing_token = current_seed.tokens[match_end+1] front_extended_landmark = landmark.clone.insert(0, preceding_token.text) if preceding_token back_extended_landmark = landmark.clone.insert(-1, trailing_token.text) if trailing_token f = current_rule.deep_clone b = current_rule.deep_clone f.landmarks[index] = front_extended_landmark if front_extended_landmark b.landmarks[index] = back_extended_landmark if back_extended_landmark refined_rules << f refined_rules.concat f.generalise_feature(index, 0) refined_rules << b refined_rules.concat b.generalise_feature(index, -1) end @candidates.concat refined_rules Log.debug "#{refined_rules.size} landmark refinements generated" return refined_rules.size end |