Skip to content

Commit

Permalink
update tokenizer regex (#58)
Browse files Browse the repository at this point in the history
* update tokenizer regex

* keep word regex and just handle underscores

* update unit test

* remove square brackets in regex
  • Loading branch information
rmillikin authored Jun 12, 2024
1 parent 50ddb11 commit 387ce5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/indexing/km_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def write_all_lines(path: str, items: 'list[str]') -> None:
def get_tokens(text: str) -> 'list[str]':
l_text = text.lower()
tokens = tokenizer.tokenize(l_text)

# remove underscores
if '_' in text:
new_tokens = []

for token in tokens:
spl = token.split('_')
new_tokens.extend(spl)

tokens = new_tokens

return tokens

def sanitize_text(text: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_index_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def delete_existing_index(data_dir):
assert not os.path.exists(index_dir)

def test_tokenization():
text = "The quick brown fox jumped over the lazy dog."
text = "The_quick brown fox jumped over the lazy dog."

tokens = util.get_tokens(text)
assert "the" in tokens
Expand Down

0 comments on commit 387ce5c

Please sign in to comment.