Debian Codegraph @

lunr/languages/trimmer.py

raw
1 import re
2
3
4 def generate_trimmer(word_characters):
5 """Returns a trimmer function from a string of word characters.
6
7 TODO: lunr-languages ships with lists of word characters for each language
8 I haven't found an equivalent in Python, we may need to copy it.
9 """
10 full_re = re.compile(r"^[^{0}]*?([{0}]+)[^{0}]*?$".format(word_characters))
11
12 def trimmer(token, i=None, tokens=None):
13 def trim(s, metadata=None):
14 match = full_re.match(s)
15 if match is None:
16 return s
17 return match.group(1)
18
19 return token.update(trim)
20
21 return trimmer