unobtanium_segmenter/augmentation/
detect_script.rs

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