harper_core/patterns/
upos_set.rs1use harper_brill::UPOS;
2use smallvec::{SmallVec, ToSmallVec};
3
4use crate::Token;
5
6use super::Pattern;
7
8pub struct UPOSSet {
9 allowed_tags: SmallVec<[UPOS; 10]>,
10}
11
12impl UPOSSet {
13 pub fn new(allowed: &[UPOS]) -> Self {
14 Self {
15 allowed_tags: allowed.to_smallvec(),
16 }
17 }
18}
19
20impl Pattern for UPOSSet {
21 fn matches(&self, tokens: &[Token], _source: &[char]) -> Option<usize> {
22 tokens.first()?.kind.as_word()?.as_ref().and_then(|w| {
23 if self.allowed_tags.contains(&(w.pos_tag?)) {
24 Some(1)
25 } else {
26 None
27 }
28 })
29 }
30}