2017-01-11 17:54:24 +00:00
|
|
|
# coding: utf-8
|
2016-10-23 13:50:04 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-01-11 17:54:24 +00:00
|
|
|
from ...pipeline import EntityRecognizer
|
|
|
|
from ..util import get_doc
|
2016-10-23 13:50:04 +00:00
|
|
|
|
2017-01-11 17:54:24 +00:00
|
|
|
import pytest
|
2016-10-23 13:50:04 +00:00
|
|
|
|
|
|
|
|
2017-01-11 17:54:24 +00:00
|
|
|
def test_add_entities_set_ents_iob(en_vocab):
|
|
|
|
text = ["This", "is", "a", "lion"]
|
|
|
|
doc = get_doc(en_vocab, text)
|
|
|
|
ner = EntityRecognizer(en_vocab, features=[(2,), (3,)])
|
|
|
|
ner(doc)
|
2016-10-23 13:50:04 +00:00
|
|
|
|
|
|
|
assert len(list(doc.ents)) == 0
|
2017-01-11 17:54:24 +00:00
|
|
|
assert [w.ent_iob_ for w in doc] == (['O'] * len(doc))
|
|
|
|
|
2016-10-23 13:50:04 +00:00
|
|
|
doc.ents = [(doc.vocab.strings['ANIMAL'], 3, 4)]
|
2017-01-11 17:54:24 +00:00
|
|
|
assert [w.ent_iob_ for w in doc] == ['O', 'O', 'O', 'B']
|
|
|
|
|
2016-10-23 13:50:04 +00:00
|
|
|
doc.ents = [(doc.vocab.strings['WORD'], 0, 2)]
|
2017-01-11 17:54:24 +00:00
|
|
|
assert [w.ent_iob_ for w in doc] == ['B', 'I', 'O', 'O']
|