2017-01-11 20:54:56 +03:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
2016-01-16 19:41:25 +03:00
|
|
|
|
2017-01-11 20:54:56 +03:00
|
|
|
import numpy
|
2018-07-25 00:38:44 +03:00
|
|
|
from spacy.attrs import HEAD, DEP
|
|
|
|
from spacy.symbols import nsubj, dobj, amod, nmod, conj, cc, root
|
|
|
|
from spacy.lang.en.syntax_iterators import SYNTAX_ITERATORS
|
|
|
|
|
|
|
|
from ...util import get_doc
|
2017-01-11 20:54:56 +03:00
|
|
|
|
|
|
|
|
2017-06-05 17:39:04 +03:00
|
|
|
def test_en_noun_chunks_not_nested(en_tokenizer):
|
2017-01-11 20:54:56 +03:00
|
|
|
text = "Peter has chronic command and control issues"
|
|
|
|
heads = [1, 0, 4, 3, -1, -2, -5]
|
|
|
|
deps = ['nsubj', 'ROOT', 'amod', 'nmod', 'cc', 'conj', 'dobj']
|
|
|
|
tokens = en_tokenizer(text)
|
2018-07-25 00:38:44 +03:00
|
|
|
doc = get_doc(tokens.vocab, words=[t.text for t in tokens], heads=heads, deps=deps)
|
2016-01-16 19:41:25 +03:00
|
|
|
tokens.from_array(
|
|
|
|
[HEAD, DEP],
|
2017-01-11 20:54:56 +03:00
|
|
|
numpy.asarray([[1, nsubj], [0, root], [4, amod], [3, nmod], [-1, cc],
|
2017-05-28 16:10:22 +03:00
|
|
|
[-2, conj], [-5, dobj]], dtype='uint64'))
|
2017-06-05 17:39:04 +03:00
|
|
|
tokens.noun_chunks_iterator = SYNTAX_ITERATORS['noun_chunks']
|
2016-01-16 19:41:25 +03:00
|
|
|
word_occurred = {}
|
|
|
|
for chunk in tokens.noun_chunks:
|
|
|
|
for word in chunk:
|
|
|
|
word_occurred.setdefault(word.text, 0)
|
|
|
|
word_occurred[word.text] += 1
|
|
|
|
for word, freq in word_occurred.items():
|
|
|
|
assert freq == 1, (word, [chunk.text for chunk in tokens.noun_chunks])
|