Skip to main content

tantivy_stemmers/
algorithms.rs

1use std::borrow::Cow;
2
3use super::snowball;
4
5pub type Algorithm = fn(&str) -> Cow<str>;
6
7// Non-Snowball algorithms
8
9#[cfg(any(feature = "polish_yarovoy", feature = "polish_yarovoy_unaccented"))]
10mod polish_yarovoy;
11
12#[cfg(feature = "polish_yarovoy")]
13pub fn polish_yarovoy<'a>(input: &'a str) -> Cow<'a, str> {
14    polish_yarovoy::stem(input, false)
15}
16
17#[cfg(feature = "polish_yarovoy_unaccented")]
18pub fn polish_yarovoy_unaccented<'a>(input: &'a str) -> Cow<'a, str> {
19    polish_yarovoy::stem(input, true)
20}
21
22// Snowball algorithms
23
24fn stem_with_snowball<'a>(stem: fn(&mut snowball::env::SnowballEnv) -> bool, input: &'a str) -> Cow<'a, str> {
25    let mut env = snowball::env::SnowballEnv::create(input);
26    stem(&mut env);
27    env.get_current()
28}
29
30#[cfg(feature = "arabic")]
31pub fn arabic<'a>(input: &'a str) -> Cow<'a, str> {
32    stem_with_snowball(snowball::algorithms::arabic, input)
33}
34
35#[cfg(feature = "armenian_mkrtchyan")]
36pub fn armenian_mkrtchyan<'a>(input: &'a str) -> Cow<'a, str> {
37    stem_with_snowball(snowball::algorithms::armenian_mkrtchyan, input)
38}
39
40#[cfg(feature = "basque")]
41pub fn basque<'a>(input: &'a str) -> Cow<'a, str> {
42    stem_with_snowball(snowball::algorithms::basque, input)
43}
44
45#[cfg(feature = "catalan")]
46pub fn catalan<'a>(input: &'a str) -> Cow<'a, str> {
47    stem_with_snowball(snowball::algorithms::catalan, input)
48}
49
50#[cfg(feature = "czech_dolamic_aggressive")]
51pub fn czech_dolamic_aggressive<'a>(input: &'a str) -> Cow<'a, str> {
52    stem_with_snowball(snowball::algorithms::czech_dolamic_aggressive, input)
53}
54
55#[cfg(feature = "czech_dolamic_light")]
56pub fn czech_dolamic_light<'a>(input: &'a str) -> Cow<'a, str> {
57    stem_with_snowball(snowball::algorithms::czech_dolamic_light, input)
58}
59
60#[cfg(feature = "danish")]
61pub fn danish<'a>(input: &'a str) -> Cow<'a, str> {
62    stem_with_snowball(snowball::algorithms::danish, input)
63}
64
65#[cfg(feature = "dutch")]
66pub fn dutch<'a>(input: &'a str) -> Cow<'a, str> {
67    stem_with_snowball(snowball::algorithms::dutch, input)
68}
69
70#[cfg(feature = "english_lovins")]
71pub fn english_lovins<'a>(input: &'a str) -> Cow<'a, str> {
72    stem_with_snowball(snowball::algorithms::english_lovins, input)
73}
74
75#[cfg(feature = "english_porter")]
76pub fn english_porter<'a>(input: &'a str) -> Cow<'a, str> {
77    stem_with_snowball(snowball::algorithms::english_porter, input)
78}
79
80#[cfg(feature = "english_porter_2")]
81pub fn english_porter_2<'a>(input: &'a str) -> Cow<'a, str> {
82    stem_with_snowball(snowball::algorithms::english_porter_2, input)
83}
84
85#[cfg(feature = "estonian_freienthal")]
86pub fn estonian_freienthal<'a>(input: &'a str) -> Cow<'a, str> {
87    stem_with_snowball(snowball::algorithms::estonian_freienthal, input)
88}
89
90#[cfg(feature = "finnish")]
91pub fn finnish<'a>(input: &'a str) -> Cow<'a, str> {
92    stem_with_snowball(snowball::algorithms::finnish, input)
93}
94
95#[cfg(feature = "french")]
96pub fn french<'a>(input: &'a str) -> Cow<'a, str> {
97    stem_with_snowball(snowball::algorithms::french, input)
98}
99
100#[cfg(feature = "german")]
101pub fn german<'a>(input: &'a str) -> Cow<'a, str> {
102    stem_with_snowball(snowball::algorithms::german, input)
103}
104
105#[cfg(feature = "greek")]
106pub fn greek<'a>(input: &'a str) -> Cow<'a, str> {
107    stem_with_snowball(snowball::algorithms::greek, input)
108}
109
110#[cfg(feature = "hindi_lightweight")]
111pub fn hindi_lightweight<'a>(input: &'a str) -> Cow<'a, str> {
112    stem_with_snowball(snowball::algorithms::hindi_lightweight, input)
113}
114
115#[cfg(feature = "hungarian")]
116pub fn hungarian<'a>(input: &'a str) -> Cow<'a, str> {
117    stem_with_snowball(snowball::algorithms::hungarian, input)
118}
119
120#[cfg(feature = "indonesian_tala")]
121pub fn indonesian_tala<'a>(input: &'a str) -> Cow<'a, str> {
122    stem_with_snowball(snowball::algorithms::indonesian_tala, input)
123}
124
125#[cfg(feature = "irish_gaelic")]
126pub fn irish_gaelic<'a>(input: &'a str) -> Cow<'a, str> {
127    stem_with_snowball(snowball::algorithms::irish_gaelic, input)
128}
129
130#[cfg(feature = "italian")]
131pub fn italian<'a>(input: &'a str) -> Cow<'a, str> {
132    stem_with_snowball(snowball::algorithms::italian, input)
133}
134
135#[cfg(feature = "lithuanian_jocas")]
136pub fn lithuanian_jocas<'a>(input: &'a str) -> Cow<'a, str> {
137    stem_with_snowball(snowball::algorithms::lithuanian_jocas, input)
138}
139
140#[cfg(feature = "nepali")]
141pub fn nepali<'a>(input: &'a str) -> Cow<'a, str> {
142    stem_with_snowball(snowball::algorithms::nepali, input)
143}
144
145#[cfg(feature = "norwegian_bokmal")]
146pub fn norwegian_bokmal<'a>(input: &'a str) -> Cow<'a, str> {
147    stem_with_snowball(snowball::algorithms::norwegian_bokmal, input)
148}
149
150#[cfg(feature = "portuguese")]
151pub fn portuguese<'a>(input: &'a str) -> Cow<'a, str> {
152    stem_with_snowball(snowball::algorithms::portuguese, input)
153}
154
155#[cfg(feature = "romanian_heidelberg")]
156pub fn romanian_heidelberg<'a>(input: &'a str) -> Cow<'a, str> {
157    stem_with_snowball(snowball::algorithms::romanian_heidelberg, input)
158}
159
160#[cfg(feature = "romanian_tirdea")]
161pub fn romanian_tirdea<'a>(input: &'a str) -> Cow<'a, str> {
162    stem_with_snowball(snowball::algorithms::romanian_tirdea, input)
163}
164
165#[cfg(feature = "romanian")]
166pub fn romanian<'a>(input: &'a str) -> Cow<'a, str> {
167    stem_with_snowball(snowball::algorithms::romanian, input)
168}
169
170#[cfg(feature = "russian")]
171pub fn russian<'a>(input: &'a str) -> Cow<'a, str> {
172    stem_with_snowball(snowball::algorithms::russian, input)
173}
174
175#[cfg(feature = "spanish")]
176pub fn spanish<'a>(input: &'a str) -> Cow<'a, str> {
177    stem_with_snowball(snowball::algorithms::spanish, input)
178}
179
180#[cfg(feature = "swedish")]
181pub fn swedish<'a>(input: &'a str) -> Cow<'a, str> {
182    stem_with_snowball(snowball::algorithms::swedish, input)
183}
184
185#[cfg(feature = "turkish_cilden")]
186pub fn turkish_cilden<'a>(input: &'a str) -> Cow<'a, str> {
187    stem_with_snowball(snowball::algorithms::turkish_cilden, input)
188}
189
190#[cfg(feature = "yiddish_urieli")]
191pub fn yiddish_urieli<'a>(input: &'a str) -> Cow<'a, str> {
192    stem_with_snowball(snowball::algorithms::yiddish_urieli, input)
193}
194