1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//! Multilingual building blocks for intent classification (#591).
//!
//! `intent_engine::PHRASE_RULES` only understands English keywords, so
//! non-English tasks ("räum die Funktion auf") used to fall back to
//! Explore/0.3. This module adds language support without ML:
//! verb-stem tables (de/fr/es), function-word language detection, and
//! per-language stopword lists.
use super::intent_engine::TaskType;
/// Verb stems matched via `word.starts_with(stem)` — morphology-tolerant
/// ("beheb" matches behebe/beheben/behebt). Entries containing a space are
/// matched as substrings of the whole lowercased query, like PHRASE_RULES.
///
/// Every stem is vetted against common English vocabulary so it cannot
/// shadow an English rule (e.g. "genera" is excluded because it would match
/// "general"; "implementa" because it would match "implementation").
pub(crate) const STEM_RULES: &[(&[&str], TaskType, f64)] = &[
(
&[
// de
"erstell",
"schreib",
"implementier",
"generier",
"hinzufüg",
"baue",
// fr
"ajout",
"crée",
"créer",
"implément",
"écri",
// es
"crea",
"añad",
"agreg",
"escrib",
],
TaskType::Generate,
0.9,
),
(
&[
// de
"beheb",
"korrigier",
"fehler",
"kaputt",
"funktioniert nicht",
"geht nicht",
"stürzt ab",
// de/fr/es (reparieren / réparer / reparar)
"repar",
"répar",
// fr
"corrig",
"ne fonctionne pas",
// es
"correg",
"arregl",
"soluciona",
"no funciona",
],
TaskType::FixBug,
0.95,
),
(
&[
// de
"refaktor",
"aufräum",
"räum",
"bereinig",
"vereinfach",
"umbenenn",
"restruktur",
"extrahier",
// en/de/fr/es shared roots
"refactor",
"reorganis",
"reorganiz",
"simplifi",
// fr
"nettoi",
"renomm",
// es
"limpi",
],
TaskType::Refactor,
0.9,
),
(
&[
// de
"erklär",
"zeig",
"versteh",
"warum",
"wieso",
"wie funktioniert",
"was macht",
"wo ist",
// fr
"pourquoi",
"expliqu",
"montre",
"cherch",
"comprend",
"comment fonctionne",
"à quoi sert",
// es
"explica",
"explíc",
"busca",
"busqu",
"muestr",
"dónde",
"cómo",
"qué hace",
"por qué",
],
TaskType::Explore,
0.85,
),
// 0.92 (not 0.9) breaks the tie against Generate verbs so that
// "schreibe tests" / "écris des tests" routes to Test — mirroring the
// English "unit test" phrase bonus.
(
&["test", "prüf", "verifizi", "vérifi", "verific", "prueb"],
TaskType::Test,
0.92,
),
(
&["debugg", "untersuch", "diagnos", "débog", "depur"],
TaskType::Debug,
0.9,
),
(
&["konfigurier", "einricht", "einstell", "instal", "configur"],
TaskType::Config,
0.85,
),
(
&[
"veröffentlich",
"publizier",
"publie",
"déploi",
"despleg",
"despli",
],
TaskType::Deploy,
0.85,
),
(
&[
"überprüf",
"begutacht",
"bewert",
"kontrollier",
"évalu",
"evalu",
"revis",
"révis",
],
TaskType::Review,
0.8,
),
];
/// Urgency markers beyond the English list in `detect_urgency`.
pub(crate) const URGENT_WORDS_I18N: &[&str] = &[
"dringend",
"sofort",
"umgehend",
"kritisch",
"urgente",
"urgence",
"immédiat",
"inmediat",
"critique",
"crítico",
];
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum QueryLang {
En,
De,
Fr,
Es,
}
const EN_MARKERS: &[&str] = &[
"the", "and", "is", "not", "with", "for", "on", "please", "can", "what", "how", "why", "this",
"that", "of", "in", "it", "to", "does", "me",
];
const DE_MARKERS: &[&str] = &[
"der", "die", "das", "und", "ist", "nicht", "ein", "eine", "mit", "für", "auf", "bitte",
"kannst", "möchte", "dass", "wie", "den", "dem", "beim", "ich",
];
const FR_MARKERS: &[&str] = &[
"le", "les", "est", "pas", "dans", "pour", "sur", "qui", "cette", "vous", "peux", "fais",
"une", "des", "ce", "que", "moi", "du",
];
const ES_MARKERS: &[&str] = &[
"el", "los", "las", "una", "en", "para", "por", "qué", "cómo", "esta", "puedes", "quiero",
"esto", "hay", "del", "lo", "que", "la",
];
/// Function-word overlap detection: cheap, deterministic, no ML.
/// Expects lowercased words. Ties (incl. all-zero) resolve to English.
pub(crate) fn detect_query_lang(words: &[&str]) -> QueryLang {
let count = |markers: &[&str]| -> usize {
words
.iter()
.filter(|w| {
let w = w.trim_matches(|c: char| !c.is_alphanumeric());
markers.contains(&w)
})
.count()
};
let mut best = QueryLang::En;
let mut best_n = count(EN_MARKERS);
for (lang, markers) in [
(QueryLang::De, DE_MARKERS),
(QueryLang::Fr, FR_MARKERS),
(QueryLang::Es, ES_MARKERS),
] {
let n = count(markers);
if n > best_n {
best = lang;
best_n = n;
}
}
best
}
// Only words that survive the `len > 3` byte filter in extract_keywords
// matter here; short articles are filtered before stopwords apply.
const DE_STOPWORDS: &[&str] = &[
"bitte", "kannst", "kann", "möchte", "mache", "machen", "eine", "einen", "einem", "einer",
"nicht", "auch", "noch", "dann", "wenn", "aber", "oder", "dass", "sind", "wird", "werden",
"sollte", "könnte", "müssen", "diese", "dieser", "dieses", "alle", "beim", "über", "für",
"danke", "dich", "mein", "sein",
];
const FR_STOPWORDS: &[&str] = &[
"dans", "pour", "cette", "vous", "avec", "mais", "plus", "tout", "être", "fait", "faire",
"fais", "elle", "sont", "cela", "ceci", "comme", "ainsi", "plaît", "peux", "veux", "merci",
"s'il", "nous", "leur",
];
const ES_STOPWORDS: &[&str] = &[
"para", "como", "cómo", "este", "esta", "esto", "todo", "pero", "más", "unos", "unas",
"puedes", "quiero", "favor", "hace", "tiene", "cuando", "aquí", "gracias", "ahora", "también",
"donde", "dónde",
];
/// Language-specific stopwords (expects a lowercased word).
/// English stopwords stay in `intent_engine::is_stop_word`.
pub(crate) fn is_stop_word_for(lang: QueryLang, w: &str) -> bool {
let list: &[&str] = match lang {
QueryLang::En => return false,
QueryLang::De => DE_STOPWORDS,
QueryLang::Fr => FR_STOPWORDS,
QueryLang::Es => ES_STOPWORDS,
};
list.contains(&w)
}
#[cfg(test)]
mod tests {
use super::*;
fn lang_of(q: &str) -> QueryLang {
let q = q.to_lowercase();
let words: Vec<&str> = q.split_whitespace().collect();
detect_query_lang(&words)
}
#[test]
fn detects_german() {
assert_eq!(lang_of("bitte räum die Funktion auf"), QueryLang::De);
assert_eq!(lang_of("kannst du den Fehler beheben?"), QueryLang::De);
}
#[test]
fn detects_french() {
assert_eq!(
lang_of("peux-tu corriger le bug dans ce module"),
QueryLang::Fr
);
}
#[test]
fn detects_spanish() {
assert_eq!(
lang_of("puedes corregir el error en la función"),
QueryLang::Es
);
}
#[test]
fn defaults_to_english() {
assert_eq!(lang_of("fix the bug in auth.rs"), QueryLang::En);
assert_eq!(lang_of("xyz qqq bbb"), QueryLang::En);
}
#[test]
fn stems_do_not_shadow_common_english() {
// English words that previously caused vetting rejections (e.g.
// "genera" → "general") must not be caught by any single-token stem.
// Aligned overlaps like "crea"→"created" (same type as the English
// rule) are intentional and not listed here.
let dangerous = [
"general",
"implementation",
"public",
"comment",
"where",
"review",
"explicit",
"instead",
"despite",
];
for word in dangerous {
for &(stems, task_type, _) in STEM_RULES {
for stem in stems.iter().filter(|s| !s.contains(' ')) {
assert!(
!word.starts_with(stem),
"stem '{stem}' ({task_type:?}) shadows English word '{word}'"
);
}
}
}
}
}