mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-11 12:18:04 +03:00
* Upd tests
This commit is contained in:
parent
5edac11225
commit
571b6eda88
|
@ -4,7 +4,10 @@ import pytest
|
||||||
def test_initial(EN):
|
def test_initial(EN):
|
||||||
doc = EN.tokenizer(u'I ate the pizza with anchovies.')
|
doc = EN.tokenizer(u'I ate the pizza with anchovies.')
|
||||||
EN.tagger(doc)
|
EN.tagger(doc)
|
||||||
next_actions = EN.parser.partial(doc, ['L-nsubj', 'S', 'L-det'])
|
with EN.parser.step_through(doc) as stepwise:
|
||||||
|
stepwise.transition('L-nsubj')
|
||||||
|
stepwise.transition('S')
|
||||||
|
stepwise.transition('L-det')
|
||||||
assert doc[0].head.i == 1
|
assert doc[0].head.i == 1
|
||||||
assert doc[1].head.i == 1
|
assert doc[1].head.i == 1
|
||||||
assert doc[2].head.i == 3
|
assert doc[2].head.i == 3
|
||||||
|
|
|
@ -3,7 +3,7 @@ import pytest
|
||||||
|
|
||||||
from spacy.strings import StringStore
|
from spacy.strings import StringStore
|
||||||
from spacy.matcher import *
|
from spacy.matcher import *
|
||||||
from spacy.attrs import ORTH
|
from spacy.attrs import LOWER
|
||||||
from spacy.tokens.doc import Doc
|
from spacy.tokens.doc import Doc
|
||||||
from spacy.vocab import Vocab
|
from spacy.vocab import Vocab
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ def matcher(EN):
|
||||||
patterns = {
|
patterns = {
|
||||||
'Javascript': ['PRODUCT', {}, [[{'ORTH': 'JavaScript'}]]],
|
'Javascript': ['PRODUCT', {}, [[{'ORTH': 'JavaScript'}]]],
|
||||||
'GoogleNow': ['PRODUCT', {}, [[{'ORTH': 'Google'}, {'ORTH': 'Now'}]]],
|
'GoogleNow': ['PRODUCT', {}, [[{'ORTH': 'Google'}, {'ORTH': 'Now'}]]],
|
||||||
'Java': ['PRODUCT', {}, [[{'ORTH': 'Java'}]]],
|
'Java': ['PRODUCT', {}, [[{'LOWER': 'java'}]]],
|
||||||
}
|
}
|
||||||
return Matcher(EN.vocab, patterns)
|
return Matcher(EN.vocab, patterns)
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ def test_match_start(matcher, EN):
|
||||||
|
|
||||||
|
|
||||||
def test_match_end(matcher, EN):
|
def test_match_end(matcher, EN):
|
||||||
tokens = EN('I like Java')
|
tokens = EN('I like java')
|
||||||
assert matcher(tokens) == [(EN.vocab.strings['PRODUCT'], 2, 3)]
|
assert matcher(tokens) == [(EN.vocab.strings['PRODUCT'], 2, 3)]
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,17 +43,17 @@ def test_match_middle(matcher, EN):
|
||||||
|
|
||||||
|
|
||||||
def test_match_multi(matcher, EN):
|
def test_match_multi(matcher, EN):
|
||||||
tokens = EN('I like Google Now and Java best')
|
tokens = EN('I like Google Now and java best')
|
||||||
assert matcher(tokens) == [(EN.vocab.strings['PRODUCT'], 2, 4),
|
assert matcher(tokens) == [(EN.vocab.strings['PRODUCT'], 2, 4),
|
||||||
(EN.vocab.strings['PRODUCT'], 5, 6)]
|
(EN.vocab.strings['PRODUCT'], 5, 6)]
|
||||||
|
|
||||||
|
|
||||||
def test_match_preserved(matcher, EN):
|
def test_match_preserved(matcher, EN):
|
||||||
doc = EN.tokenizer('I like Java')
|
doc = EN.tokenizer('I like java')
|
||||||
EN.tagger(doc)
|
EN.tagger(doc)
|
||||||
EN.entity(doc)
|
EN.entity(doc)
|
||||||
assert len(doc.ents) == 0
|
assert len(doc.ents) == 0
|
||||||
doc = EN.tokenizer('I like Java')
|
doc = EN.tokenizer('I like java')
|
||||||
matcher(doc)
|
matcher(doc)
|
||||||
assert len(doc.ents) == 1
|
assert len(doc.ents) == 1
|
||||||
EN.tagger(doc)
|
EN.tagger(doc)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user