Skip to content

Commit

Permalink
fix absorptions
Browse files Browse the repository at this point in the history
  • Loading branch information
xsandr committed Dec 22, 2015
1 parent 87cd6b4 commit a2ac640
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ta4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def get_whole_markers(words):
def absorptions(phrases):
u"""
Поглощения фраз
Каждая фраза должна
на вход список фраз/вхождений - [("one phrase", 10), ("phrase", 2)]
"""
phrases = [(Sentence(phrase), count) for phrase, count in phrases]
Expand All @@ -167,6 +166,9 @@ def absorptions(phrases):
for i, (phrase, count) in enumerate(phrases):
for j in range(i+1, len(phrases)):
(candidate, cand_count) = phrases[j]
# Поглащаются фразы со *, только при одинаковой длинне
if phrase.is_special and len(phrase) != len(candidate):
continue
if is_contains(candidate, phrase):
count -= 1
results.append((phrase, count))
Expand Down
8 changes: 8 additions & 0 deletions tests/test_absorptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
[(u"купить деревянный стол", 10),
(u"купить * стол", 11)],
),
(
[(u"купить длинный деревянный стол", 10),
(u"купить * деревянный стол", 12),
(u"купить * деревянный", 12)],
[(u"купить длинный деревянный стол", 10),
(u"купить * деревянный стол", 11),
(u"купить * деревянный", 12)],
),
])
def test_absorptions(input, result):
assert set(absorptions(input)) == set(result)
Expand Down

0 comments on commit a2ac640

Please sign in to comment.