Debian Codegraph @

lunr/stop_word_filter.py

raw
1 from lunr.pipeline import Pipeline
2
3 WORDS = {
4 "a",
5 "able",
6 "about",
7 "across",
8 "after",
9 "all",
10 "almost",
11 "also",
12 "am",
13 "among",
14 "an",
15 "and",
16 "any",
17 "are",
18 "as",
19 "at",
20 "be",
21 "because",
22 "been",
23 "but",
24 "by",
25 "can",
26 "cannot",
27 "could",
28 "dear",
29 "did",
30 "do",
31 "does",
32 "either",
33 "else",
34 "ever",
35 "every",
36 "for",
37 "from",
38 "get",
39 "got",
40 "had",
41 "has",
42 "have",
43 "he",
44 "her",
45 "hers",
46 "him",
47 "his",
48 "how",
49 "however",
50 "i",
51 "if",
52 "in",
53 "into",
54 "is",
55 "it",
56 "its",
57 "just",
58 "least",
59 "let",
60 "like",
61 "likely",
62 "may",
63 "me",
64 "might",
65 "most",
66 "must",
67 "my",
68 "neither",
69 "no",
70 "nor",
71 "not",
72 "of",
73 "off",
74 "often",
75 "on",
76 "only",
77 "or",
78 "other",
79 "our",
80 "own",
81 "rather",
82 "said",
83 "say",
84 "says",
85 "she",
86 "should",
87 "since",
88 "so",
89 "some",
90 "than",
91 "that",
92 "the",
93 "their",
94 "them",
95 "then",
96 "there",
97 "these",
98 "they",
99 "this",
100 "tis",
101 "to",
102 "too",
103 "twas",
104 "us",
105 "wants",
106 "was",
107 "we",
108 "were",
109 "what",
110 "when",
111 "where",
112 "which",
113 "while",
114 "who",
115 "whom",
116 "why",
117 "will",
118 "with",
119 "would",
120 "yet",
121 "you",
122 "your",
123 }
124
125
126 def generate_stop_word_filter(stop_words, language=None):
127 """Builds a stopWordFilter function from the provided list of stop words.
128
129 The built in `stop_word_filter` is built using this factory and can be used
130 to generate custom `stop_word_filter` for applications or non English
131 languages.
132 """
133
134 def stop_word_filter(token, i=None, tokens=None):
135 if token and str(token) not in stop_words:
136 return token
137
138 # camelCased for for compatibility with lunr.js
139 label = (
140 "stopWordFilter-{}".format(language)
141 if language is not None
142 else "stopWordFilter"
143 )
144 Pipeline.register_function(stop_word_filter, label)
145 return stop_word_filter
146
147
148 stop_word_filter = generate_stop_word_filter(WORDS)