Module nlprule::rule::id [−][src]
Provides structures to identify nodes at various levels of the rule tree and a Selector to match on these structs.
Rules are nested in up to three layers in the original XML:
<category ...>
<rulegroup ...> <!-- can be omitted, there's also <rule>s at this level -->
<rule ...>
</rule>
</rulegroup>
</category>
The Category, Group and Index structs provide a way to identify these layers.
Examples
Select individal rules:
use nlprule::{Tokenizer, Rules, rule::id::Category}; use std::convert::TryInto; let tokenizer = Tokenizer::new("path/to/en_tokenizer.bin")?; let mut rules = Rules::new("path/to/en_rules.bin")?; // disable rules named "confusion_due_do" in category "confused_words" rules .select_mut( &Category::new("confused_words") .join("confusion_due_do") .into(), ) .for_each(|rule| rule.disable()); // disable all grammar rules rules .select_mut(&Category::new("grammar").into()) .for_each(|rule| rule.disable()); // a string syntax where slashes are the separator is also supported rules .select_mut(&"confused_words/confusion_due_do".try_into()?) .for_each(|rule| rule.enable());
Structs
Category | Identifies a category. |
Group | Identifies a rule group. |
Index | Identifies the children of a rule group. Rules without a group in the original XML are treated as a rule group with one child. |
Enums
Error | |
Selector | A selector to filter rules by checking if an Index matches the selector.
Can be created from a Category, Group, or Index by casting with |