Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions parser_tool/tests/test_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ def test_tokenize_sentence_with_multi_word_expression(self):
"text": "Во время встречи он встал и вышел в коридор. В это время мы еще не поняли, в чем дело.",
"occurrences": 1,
},
{
"mwe": "Во-первых",
"text": "Во-первых, нужно понять суть проблемы.",
"occurrences": 1,
},
{
"mwe": "Во-вторых",
"text": "Во-вторых, следует найти решение.",
"occurrences": 1,
},
{
"mwe": "В-третьих",
"text": "В-третьих, нужно проверить результат.",
"occurrences": 1,
},
{
"mwe": "Во-первы́х",
"text": "Во-первы́х, это очень важно.",
"occurrences": 1,
},
{
"mwe": "Во-вторы́х",
"text": "Во-вторы́х, нужно быть осторожным.",
"occurrences": 1,
},
{
"mwe": "В-тре́тьих",
"text": "В-тре́тьих, это последний пункт.",
"occurrences": 1,
},
]
for test in tests:
(mwe, text, expected_occurrences) = test["mwe"], test["text"], test["occurrences"]
Expand Down
5 changes: 4 additions & 1 deletion parser_tool/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,13 @@ def split_hyphenated(tokens, hyphen_char=HYPHEN_CHAR, reserved_words=HYPHENATED_
"""
Splits hyphenated tokens, handling special cases like "по-" words, which should not be split.
"""
# Create a set of canonical forms of reserved words for faster lookup
canonical_reserved_words = {canonical(word) for word in reserved_words}

new_tokens = []
for token in tokens:
# split hyphenated unless it's a special case like "по-" words (DB entries for those)
if hyphen_char in token and not token.startswith("по-") and token not in reserved_words:
if hyphen_char in token and not token.lower().startswith("по-") and canonical(token) not in canonical_reserved_words:
for t in re.split(r"(%s)" % hyphen_char, token):
if t != "":
new_tokens.append(t)
Expand Down