mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-11 04:08:09 +03:00
db55577c45
* Remove unicode declarations * Remove Python 3.5 and 2.7 from CI * Don't require pathlib * Replace compat helpers * Remove OrderedDict * Use f-strings * Set Cython compiler language level * Fix typo * Re-add OrderedDict for Table * Update setup.cfg * Revert CONTRIBUTING.md * Revert lookups.md * Revert top-level.md * Small adjustments and docs [ci skip]
24 lines
838 B
Python
24 lines
838 B
Python
from spacy.matcher import PhraseMatcher
|
|
from spacy.tokens import Doc
|
|
|
|
|
|
def test_issue4002(en_vocab):
|
|
"""Test that the PhraseMatcher can match on overwritten NORM attributes.
|
|
"""
|
|
matcher = PhraseMatcher(en_vocab, attr="NORM")
|
|
pattern1 = Doc(en_vocab, words=["c", "d"])
|
|
assert [t.norm_ for t in pattern1] == ["c", "d"]
|
|
matcher.add("TEST", [pattern1])
|
|
doc = Doc(en_vocab, words=["a", "b", "c", "d"])
|
|
assert [t.norm_ for t in doc] == ["a", "b", "c", "d"]
|
|
matches = matcher(doc)
|
|
assert len(matches) == 1
|
|
matcher = PhraseMatcher(en_vocab, attr="NORM")
|
|
pattern2 = Doc(en_vocab, words=["1", "2"])
|
|
pattern2[0].norm_ = "c"
|
|
pattern2[1].norm_ = "d"
|
|
assert [t.norm_ for t in pattern2] == ["c", "d"]
|
|
matcher.add("TEST", [pattern2])
|
|
matches = matcher(doc)
|
|
assert len(matches) == 1
|