| Class | Ariel::Rule |
| In: |
lib/ariel/rule.rb
|
| Parent: | Object |
A rule contains an array of landmarks (each of which is an array of individual landmark features. This landmark array is accessible through Rule#landmarks. A Rule also has a direction :forward or :back, which determines whether it is applied from the end or beginning of a tokenstream.
| direction | [RW] | |
| exhaustive | [RW] | |
| landmarks | [RW] |
A rule’s direction can be :back or :forward, which determines whether it is applied from the start of end of the TokenStream. The landmark array contains an array for each landmark, which consists of one or more features. e.g. Rule.new([[:anything, "Example"], ["Test"]], :forward).
Reverses the given tokenstream if necessary based on its current direction, and the direction given (corresponding to the sort of rule you hope to apply to it).
Given a TokenStream and a rule, applies the rule on the stream and returns an empty array if the match fails and an array of token_locs if the match succeeds. Yields a RuleMatchData Struct with accessors token_loc (the position of the match in the stream) and type if a block is given. type is nil if the TokenStream has no label, :perfect if all tokens up to the labeled token are consumed, :early if the rule’s final position is before the labeled token, and :late if it is after. The returned token_loc is the position in the stream as it was passed in. That is, the token_loc is always from the left of the given stream whether it is in a reversed state or not.
Only used in rule learning on labeled tokenstreams. Needed to provide the match index most relevant to the currently labeled list item. A preference of :early or :late can be passed, which will only return a token_loc before the stream’s label_index or after the label_index.
Returns true or false depending on if the match of this rule on the given tokenstream is of any of the given types (could be a combination of :perfect, :early, :fail and :late). Only valid on streams with labels