mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-11 12:18:04 +03:00
c417c380e3
* allow phrasematcher to link one match to multiple original patterns * small fix for defining ent_id in the matcher (anti-ghost prevention) * cleanup * formatting
24 lines
734 B
Python
24 lines
734 B
Python
# coding: utf8
|
|
from __future__ import unicode_literals
|
|
|
|
import pytest
|
|
from spacy.matcher import PhraseMatcher
|
|
from spacy.tokens import Doc
|
|
|
|
|
|
def test_issue3972(en_vocab):
|
|
"""Test that the PhraseMatcher returns duplicates for duplicate match IDs.
|
|
"""
|
|
matcher = PhraseMatcher(en_vocab)
|
|
matcher.add("A", None, Doc(en_vocab, words=["New", "York"]))
|
|
matcher.add("B", None, Doc(en_vocab, words=["New", "York"]))
|
|
doc = Doc(en_vocab, words=["I", "live", "in", "New", "York"])
|
|
matches = matcher(doc)
|
|
|
|
assert len(matches) == 2
|
|
|
|
# We should have a match for each of the two rules
|
|
found_ids = [en_vocab.strings[ent_id] for (ent_id, _, _) in matches]
|
|
assert "A" in found_ids
|
|
assert "B" in found_ids
|