1use crate::backends::stacked::StackedNER;
2use crate::{Entity, EntityType, Model, Result};
3
4pub struct AutoNER {
10 default_model: StackedNER,
11}
12
13impl AutoNER {
14 pub fn new() -> Self {
16 Self {
17 default_model: StackedNER::default(),
18 }
19 }
20}
21
22impl Default for AutoNER {
23 fn default() -> Self {
24 Self::new()
25 }
26}
27
28impl Model for AutoNER {
29 fn extract_entities(&self, text: &str, language: Option<&str>) -> Result<Vec<Entity>> {
30 self.default_model.extract_entities(text, language)
33 }
34
35 fn supported_types(&self) -> Vec<EntityType> {
36 self.default_model.supported_types()
37 }
38
39 fn is_available(&self) -> bool {
40 self.default_model.is_available()
41 }
42
43 fn name(&self) -> &'static str {
44 "auto"
45 }
46
47 fn description(&self) -> &'static str {
48 "Automatic model selection (default: StackedNER)"
49 }
50}
51
52impl crate::sealed::Sealed for AutoNER {}
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_auto_ner_creation() {
60 let auto = AutoNER::new();
61 assert!(auto.is_available());
62 }
63
64 #[test]
65 fn test_auto_ner_default() {
66 let auto = AutoNER::default();
67 assert_eq!(auto.name(), "auto");
68 }
69
70 #[test]
71 fn test_auto_ner_extracts_entities() {
72 let auto = AutoNER::new();
73 let entities = auto
74 .extract_entities("Google CEO Sundar Pichai announced.", None)
75 .unwrap();
76 assert!(!entities.is_empty(), "AutoNER should extract entities");
78 }
79
80 #[test]
81 fn test_auto_ner_supported_types() {
82 let auto = AutoNER::new();
83 let types = auto.supported_types();
84 assert!(!types.is_empty());
86 }
87
88 #[test]
89 fn test_auto_ner_description() {
90 let auto = AutoNER::new();
91 assert!(auto.description().contains("Automatic"));
92 }
93
94 #[test]
95 fn test_auto_ner_empty_text() {
96 let auto = AutoNER::new();
97 let entities = auto.extract_entities("", None).unwrap();
98 assert!(entities.is_empty());
99 }
100}