summaryrefslogtreecommitdiffstats
path: root/sphinx/search/ru.py
blob: b8412c1e84698c2f2c45839963f3f84f22d57d65 (plain)
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
"""Russian search language: includes the JS Russian stemmer."""

from __future__ import annotations

from typing import TYPE_CHECKING, Dict

import snowballstemmer

from sphinx.search import SearchLanguage, parse_stop_word

russian_stopwords = parse_stop_word('''
| source: http://snowball.tartarus.org/algorithms/russian/stop.txt
и              | and
в              | in/into
во             | alternative form
не             | not
что            | what/that
он             | he
на             | on/onto
я              | i
с              | from
со             | alternative form
как            | how
а              | milder form of `no' (but)
то             | conjunction and form of `that'
все            | all
она            | she
так            | so, thus
его            | him
но             | but
да             | yes/and
ты             | thou
к              | towards, by
у              | around, chez
же             | intensifier particle
вы             | you
за             | beyond, behind
бы             | conditional/subj. particle
по             | up to, along
только         | only
ее             | her
мне            | to me
было           | it was
вот            | here is/are, particle
от             | away from
меня           | me
еще            | still, yet, more
нет            | no, there isnt/arent
о              | about
из             | out of
ему            | to him
теперь         | now
когда          | when
даже           | even
ну             | so, well
вдруг          | suddenly
ли             | interrogative particle
если           | if
уже            | already, but homonym of `narrower'
или            | or
ни             | neither
быть           | to be
был            | he was
него           | prepositional form of его
до             | up to
вас            | you accusative
нибудь         | indef. suffix preceded by hyphen
опять          | again
уж             | already, but homonym of `adder'
вам            | to you
сказал         | he said
ведь           | particle `after all'
там            | there
потом          | then
себя           | oneself
ничего         | nothing
ей             | to her
может          | usually with `быть' as `maybe'
они            | they
тут            | here
где            | where
есть           | there is/are
надо           | got to, must
ней            | prepositional form of  ей
для            | for
мы             | we
тебя           | thee
их             | them, their
чем            | than
была           | she was
сам            | self
чтоб           | in order to
без            | without
будто          | as if
человек        | man, person, one
чего           | genitive form of `what'
раз            | once
тоже           | also
себе           | to oneself
под            | beneath
жизнь          | life
будет          | will be
ж              | short form of intensifer particle `же'
тогда          | then
кто            | who
этот           | this
говорил        | was saying
того           | genitive form of `that'
потому         | for that reason
этого          | genitive form of `this'
какой          | which
совсем         | altogether
ним            | prepositional form of `его', `они'
здесь          | here
этом           | prepositional form of `этот'
один           | one
почти          | almost
мой            | my
тем            | instrumental/dative plural of `тот', `то'
чтобы          | full form of `in order that'
нее            | her (acc.)
кажется        | it seems
сейчас         | now
были           | they were
куда           | where to
зачем          | why
сказать        | to say
всех           | all (acc., gen. preposn. plural)
никогда        | never
сегодня        | today
можно          | possible, one can
при            | by
наконец        | finally
два            | two
об             | alternative form of `о', about
другой         | another
хоть           | even
после          | after
над            | above
больше         | more
тот            | that one (masc.)
через          | across, in
эти            | these
нас            | us
про            | about
всего          | in all, only, of all
них            | prepositional form of `они' (they)
какая          | which, feminine
много          | lots
разве          | interrogative particle
сказала        | she said
три            | three
эту            | this, acc. fem. sing.
моя            | my, feminine
впрочем        | moreover, besides
хорошо         | good
свою           | ones own, acc. fem. sing.
этой           | oblique form of `эта', fem. `this'
перед          | in front of
иногда         | sometimes
лучше          | better
чуть           | a little
том            | preposn. form of `that one'
нельзя         | one must not
такой          | such a one
им             | to them
более          | more
всегда         | always
конечно        | of course
всю            | acc. fem. sing of `all'
между          | between


  | b: some paradigms
  |
  | personal pronouns
  |
  | я  меня  мне  мной  [мною]
  | ты  тебя  тебе  тобой  [тобою]
  | он  его  ему  им  [него, нему, ним]
  | она  ее  эи  ею  [нее, нэи, нею]
  | оно  его  ему  им  [него, нему, ним]
  |
  | мы  нас  нам  нами
  | вы  вас  вам  вами
  | они  их  им  ими  [них, ним, ними]
  |
  |   себя  себе  собой   [собою]
  |
  | demonstrative pronouns: этот (this), тот (that)
  |
  | этот  эта  это  эти
  | этого  эты  это  эти
  | этого  этой  этого  этих
  | этому  этой  этому  этим
  | этим  этой  этим  [этою]  этими
  | этом  этой  этом  этих
  |
  | тот  та  то  те
  | того  ту  то  те
  | того  той  того  тех
  | тому  той  тому  тем
  | тем  той  тем  [тою]  теми
  | том  той  том  тех
  |
  | determinative pronouns
  |
  | (a) весь (all)
  |
  | весь  вся  все  все
  | всего  всю  все  все
  | всего  всей  всего  всех
  | всему  всей  всему  всем
  | всем  всей  всем  [всею]  всеми
  | всем  всей  всем  всех
  |
  | (b) сам (himself etc)
  |
  | сам  сама  само  сами
  | самого саму  само  самих
  | самого самой самого  самих
  | самому самой самому  самим
  | самим  самой  самим  [самою]  самими
  | самом самой самом  самих
  |
  | stems of verbs `to be', `to have', `to do' and modal
  |
  | быть  бы  буд  быв  есть  суть
  | име
  | дел
  | мог   мож  мочь
  | уме
  | хоч  хот
  | долж
  | можн
  | нужн
  | нельзя
''')


class SearchRussian(SearchLanguage):
    lang = 'ru'
    language_name = 'Russian'
    js_stemmer_rawcode = 'russian-stemmer.js'
    stopwords = russian_stopwords

    def init(self, options: dict) -> None:
        self.stemmer = snowballstemmer.stemmer('russian')

    def stem(self, word: str) -> str:
        return self.stemmer.stemWord(word.lower())