mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 18:26:30 +03:00
Test Issue 429: No valid actions for NER after matcher adds a new entity label.
This commit is contained in:
parent
03a520ec4f
commit
afea6505f3
29
spacy/tests/regression/test_issue429.py
Normal file
29
spacy/tests/regression/test_issue429.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from __future__ import unicode_literals
|
||||
import pytest
|
||||
|
||||
import spacy
|
||||
from spacy.attrs import ORTH
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_issue429():
|
||||
|
||||
nlp = spacy.load('en', parser=False)
|
||||
|
||||
|
||||
def merge_phrases(matcher, doc, i, matches):
|
||||
if i != len(matches) - 1:
|
||||
return None
|
||||
spans = [(ent_id, label, doc[start:end]) for ent_id, label, start, end in matches]
|
||||
for ent_id, label, span in spans:
|
||||
span.merge('NNP' if label else span.root.tag_, span.text, nlp.vocab.strings[label])
|
||||
|
||||
doc = nlp('a')
|
||||
nlp.matcher.add('key', label='TEST', attrs={}, specs=[[{ORTH: 'a'}]], on_match=merge_phrases)
|
||||
doc = nlp.tokenizer('a b c')
|
||||
nlp.tagger(doc)
|
||||
nlp.matcher(doc)
|
||||
|
||||
for word in doc:
|
||||
print(word.text, word.ent_iob_, word.ent_type_)
|
||||
nlp.entity(doc)
|
Loading…
Reference in New Issue
Block a user