unobtanium_segmenter/augmentation/
detect_script.rs

1use whatlang::detect_script;
2
3use crate::augmentation::Augmenter;
4use crate::SegmentedToken;
5
6/// Will run just script detection using [whatlang].
7#[derive(Debug, Clone, Default)]
8pub struct AugmentationDetectScript {}
9
10impl AugmentationDetectScript {
11	/// Create a new AugmentationDetectScript instance
12	pub fn new() -> Self {
13		Default::default()
14	}
15}
16
17impl Augmenter for AugmentationDetectScript {
18	fn augment<'a>(&self, mut token: SegmentedToken<'a>) -> SegmentedToken<'a> {
19		if !token.is_known_word {
20			if let Some(script) = detect_script(token.text) {
21				token.detected_script = Some(script);
22			}
23		}
24		return token;
25	}
26}