2017-01-10 18:24:10 +00:00
|
|
|
# coding: utf-8
|
2016-10-27 16:01:34 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-01-12 21:00:37 +00:00
|
|
|
from ...attrs import ORTH
|
|
|
|
from ...matcher import Matcher
|
2016-10-27 16:01:34 +00:00
|
|
|
|
2017-01-10 18:24:10 +00:00
|
|
|
import pytest
|
|
|
|
|
2016-10-27 16:01:34 +00:00
|
|
|
|
|
|
|
@pytest.mark.models
|
2017-01-12 21:00:37 +00:00
|
|
|
def test_issue429(EN):
|
2016-10-27 16:01:34 +00:00
|
|
|
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:
|
2017-01-12 21:00:37 +00:00
|
|
|
span.merge('NNP' if label else span.root.tag_, span.text, EN.vocab.strings[label])
|
|
|
|
|
|
|
|
doc = EN('a')
|
|
|
|
matcher = Matcher(EN.vocab)
|
|
|
|
matcher.add('key', label='TEST', attrs={}, specs=[[{ORTH: 'a'}]], on_match=merge_phrases)
|
|
|
|
doc = EN.tokenizer('a b c')
|
|
|
|
EN.tagger(doc)
|
|
|
|
matcher(doc)
|
|
|
|
EN.entity(doc)
|