2015-04-17 02:40:53 +03:00
|
|
|
"""Test the Token.conjuncts property"""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from spacy.en import English
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
def orths(tokens):
|
|
|
|
return [t.orth_ for t in tokens]
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_two():
|
2015-06-07 17:49:46 +03:00
|
|
|
nlp = English()
|
|
|
|
tokens = nlp('I lost money and pride.', tag=True, parse=True)
|
2015-04-17 02:40:53 +03:00
|
|
|
pride = tokens[4]
|
2015-06-07 17:49:46 +03:00
|
|
|
for t in tokens:
|
|
|
|
print t.orth_, t.tag_, t.head.orth_
|
2015-04-17 02:40:53 +03:00
|
|
|
assert orths(pride.conjuncts) == ['money', 'pride']
|
|
|
|
money = tokens[2]
|
|
|
|
assert orths(money.conjuncts) == ['money', 'pride']
|
|
|
|
|
|
|
|
|
|
|
|
def test_comma_three():
|
2015-06-07 17:49:46 +03:00
|
|
|
nlp = English()
|
|
|
|
tokens = nlp('I found my wallet, phone and keys.')
|
2015-04-17 02:40:53 +03:00
|
|
|
keys = tokens[-2]
|
|
|
|
assert orths(keys.conjuncts) == ['wallet', 'phone', 'keys']
|
|
|
|
wallet = tokens[3]
|
|
|
|
assert orths(wallet.conjuncts) == ['wallet', 'phone', 'keys']
|
|
|
|
|
|
|
|
|
2015-05-24 22:51:41 +03:00
|
|
|
# This is failing due to parse errors
|
|
|
|
#def test_and_three():
|
|
|
|
# tokens = NLU('I found my wallet and phone and keys.')
|
|
|
|
# keys = tokens[-2]
|
|
|
|
# assert orths(keys.conjuncts) == ['wallet', 'phone', 'keys']
|
|
|
|
# wallet = tokens[3]
|
|
|
|
# assert orths(wallet.conjuncts) == ['wallet', 'phone', 'keys']
|