mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-27 10:26:35 +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]
35 lines
918 B
Python
35 lines
918 B
Python
from spacy.lang.en import English
|
|
from spacy.pipeline import EntityRuler
|
|
|
|
|
|
def test_issue4267():
|
|
""" Test that running an entity_ruler after ner gives consistent results"""
|
|
nlp = English()
|
|
ner = nlp.create_pipe("ner")
|
|
ner.add_label("PEOPLE")
|
|
nlp.add_pipe(ner)
|
|
nlp.begin_training()
|
|
|
|
assert "ner" in nlp.pipe_names
|
|
|
|
# assert that we have correct IOB annotations
|
|
doc1 = nlp("hi")
|
|
assert doc1.is_nered
|
|
for token in doc1:
|
|
assert token.ent_iob == 2
|
|
|
|
# add entity ruler and run again
|
|
ruler = EntityRuler(nlp)
|
|
patterns = [{"label": "SOFTWARE", "pattern": "spacy"}]
|
|
|
|
ruler.add_patterns(patterns)
|
|
nlp.add_pipe(ruler)
|
|
assert "entity_ruler" in nlp.pipe_names
|
|
assert "ner" in nlp.pipe_names
|
|
|
|
# assert that we still have correct IOB annotations
|
|
doc2 = nlp("hi")
|
|
assert doc2.is_nered
|
|
for token in doc2:
|
|
assert token.ent_iob == 2
|