Skip to content

Commit 278f81d

Browse files
committed
Add unit tests to key_phrase_tokenizer
Signed-off-by: Mike Rombout <mike.rombout@elastisys.com>
1 parent 7f7da29 commit 278f81d

8 files changed

Lines changed: 2517 additions & 5 deletions

src/licensedcode/tokenize.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ def query_lines(location=None, query_string=None, strip=True, start_line=1):
6969
KEY_PHRASE_CLOSE = "}}"
7070

7171
def key_phrase_tokenizer(text, stopwords=STOPWORDS):
72+
"""
73+
Return an iterable of tokens from a unicode query test. It must behave identically as the `index_tokenizer` with the
74+
exception that it returns KEY_PHRASE_OPEN and KEY_PHRASE_CLOSE as separate tokens so that they can be used to parse
75+
key phrases.
76+
"""
7277
if not text:
7378
return []
7479
words = key_phrase_splitter(text.lower())
7580

7681
new_words = []
7782
for word in words:
78-
# TODO: Optimize for readability
7983
if word.startswith(KEY_PHRASE_OPEN):
8084
new_words.append(KEY_PHRASE_OPEN)
8185

tests/licensedcode/data/tokenize/htmlish.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
</div>
9494
<div class="main-cont">
9595
<div class="main-text-cont">
96-
<h1>Third party services</h1>
96+
<h1>{{Third party services}}</h1>
9797
<p>
9898
Of course we are all for responsible disclosure, which you might have seen if you have read our blog. So here we have listed all the third party services we use in different ways in alphabetical order and an added a short comment on why or how we use them.
9999
</p>

0 commit comments

Comments
 (0)