MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / query_tokenizer

Function query_tokenizer

src/licensedcode/tokenize.py:309–329  ·  view source on GitHub ↗

Return an iterable of tokens from a unicode query text. Do not ignore stop words. They are handled at a later stage in a query. For example:: >>> list(query_tokenizer('')) [] >>> x = list(query_tokenizer('some Text with spAces! + _ -')) >>> assert x == ['some', 'text'

(text)

Source from the content-addressed store, hash-verified

307
308
309def query_tokenizer(text):
310 """
311 Return an iterable of tokens from a unicode query text. Do not ignore stop
312 words. They are handled at a later stage in a query.
313
314 For example::
315 >>> list(query_tokenizer(''))
316 []
317 >>> x = list(query_tokenizer('some Text with spAces! + _ -'))
318 >>> assert x == ['some', 'text', 'with', 'spaces']
319
320 >>> x = list(query_tokenizer('{{}some }}Text with spAces! + _ -'))
321 >>> assert x == ['some', 'text', 'with', 'spaces']
322
323 >>> x = list(query_tokenizer('{{Hi}}some {{}}Text with{{noth+-_!@ing}} {{junk}}spAces! + _ -{{}}'))
324 >>> assert x == ['hi', 'some', 'text', 'with', 'noth+', 'ing', 'junk', 'spaces']
325 """
326 if not text:
327 return []
328 words = word_splitter(text.lower())
329 return (token for token in words if token)
330
331
332# Alternate pattern which is the opposite of query_pattern used for

Calls

no outgoing calls