| 7 | |
| 8 | |
| 9 | class SimpleTokenizer(object): |
| 10 | ALPHA_NUM = r'[\p{L}\p{N}\p{M}]+' |
| 11 | NON_WS = r'[^\p{Z}\p{C}]' |
| 12 | |
| 13 | def __init__(self): |
| 14 | """ |
| 15 | Args: |
| 16 | annotators: None or empty set (only tokenizes). |
| 17 | """ |
| 18 | self._regexp = regex.compile( |
| 19 | '(%s)|(%s)' % (self.ALPHA_NUM, self.NON_WS), |
| 20 | flags=regex.IGNORECASE + regex.UNICODE + regex.MULTILINE |
| 21 | ) |
| 22 | |
| 23 | def tokenize(self, text, uncased=False): |
| 24 | matches = [m for m in self._regexp.finditer(text)] |
| 25 | if uncased: |
| 26 | tokens = [m.group().lower() for m in matches] |
| 27 | else: |
| 28 | tokens = [m.group() for m in matches] |
| 29 | return tokens |
| 30 | |
| 31 | |
| 32 | def remove_articles(text): |
no outgoing calls
no test coverage detected