mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-27 10:26:35 +03:00
27 lines
766 B
Python
27 lines
766 B
Python
# coding: utf-8
|
|
from __future__ import unicode_literals
|
|
|
|
from ...matcher import Matcher
|
|
from ...attrs import LOWER
|
|
|
|
import pytest
|
|
|
|
|
|
def test_issue242(en_tokenizer):
|
|
"""Test overlapping multi-word phrases."""
|
|
text = "There are different food safety standards in different countries."
|
|
patterns = [[{LOWER: 'food'}, {LOWER: 'safety'}],
|
|
[{LOWER: 'safety'}, {LOWER: 'standards'}]]
|
|
|
|
doc = en_tokenizer(text)
|
|
matcher = Matcher(doc.vocab)
|
|
matcher.add('FOOD', 'FOOD', {}, patterns)
|
|
|
|
matches = [(ent_type, start, end) for ent_id, ent_type, start, end in matcher(doc)]
|
|
doc.ents += tuple(matches)
|
|
match1, match2 = matches
|
|
assert match1[1] == 3
|
|
assert match1[2] == 5
|
|
assert match2[1] == 4
|
|
assert match2[2] == 6
|