mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-03 21:24:11 +03:00
Merge branch 'v1.0.0-rc1' of ssh://github.com/explosion/spaCy into v1.0.0-rc1
This commit is contained in:
commit
4ba9eadf3d
|
@ -7,11 +7,11 @@ from ..de import German
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def EN():
|
def EN():
|
||||||
return English(path=False)
|
return English()
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def DE():
|
def DE():
|
||||||
return German(path=False)
|
return German()
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
|
|
|
@ -6,12 +6,12 @@ import cloudpickle
|
||||||
import io
|
import io
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.models
|
#@pytest.mark.models
|
||||||
def test_pickle(EN):
|
#def test_pickle(EN):
|
||||||
file_ = io.BytesIO()
|
# file_ = io.BytesIO()
|
||||||
cloudpickle.dump(EN.parser, file_)
|
# cloudpickle.dump(EN.parser, file_)
|
||||||
|
#
|
||||||
file_.seek(0)
|
# file_.seek(0)
|
||||||
|
#
|
||||||
loaded = pickle.load(file_)
|
# loaded = pickle.load(file_)
|
||||||
|
#
|
||||||
|
|
|
@ -24,30 +24,30 @@ def test_compile(matcher):
|
||||||
|
|
||||||
|
|
||||||
def test_no_match(matcher):
|
def test_no_match(matcher):
|
||||||
doc = Doc(matcher.vocab, ['I', 'like', 'cheese', '.'])
|
doc = Doc(matcher.vocab, words=['I', 'like', 'cheese', '.'])
|
||||||
assert matcher(doc) == []
|
assert matcher(doc) == []
|
||||||
|
|
||||||
|
|
||||||
def test_match_start(matcher):
|
def test_match_start(matcher):
|
||||||
doc = Doc(matcher.vocab, ['JavaScript', 'is', 'good'])
|
doc = Doc(matcher.vocab, words=['JavaScript', 'is', 'good'])
|
||||||
assert matcher(doc) == [(matcher.vocab.strings['JS'],
|
assert matcher(doc) == [(matcher.vocab.strings['JS'],
|
||||||
matcher.vocab.strings['PRODUCT'], 0, 1)]
|
matcher.vocab.strings['PRODUCT'], 0, 1)]
|
||||||
|
|
||||||
|
|
||||||
def test_match_end(matcher):
|
def test_match_end(matcher):
|
||||||
doc = Doc(matcher.vocab, ['I', 'like', 'java'])
|
doc = Doc(matcher.vocab, words=['I', 'like', 'java'])
|
||||||
assert matcher(doc) == [(doc.vocab.strings['Java'],
|
assert matcher(doc) == [(doc.vocab.strings['Java'],
|
||||||
doc.vocab.strings['PRODUCT'], 2, 3)]
|
doc.vocab.strings['PRODUCT'], 2, 3)]
|
||||||
|
|
||||||
|
|
||||||
def test_match_middle(matcher):
|
def test_match_middle(matcher):
|
||||||
doc = Doc(matcher.vocab, ['I', 'like', 'Google', 'Now', 'best'])
|
doc = Doc(matcher.vocab, words=['I', 'like', 'Google', 'Now', 'best'])
|
||||||
assert matcher(doc) == [(doc.vocab.strings['GoogleNow'],
|
assert matcher(doc) == [(doc.vocab.strings['GoogleNow'],
|
||||||
doc.vocab.strings['PRODUCT'], 2, 4)]
|
doc.vocab.strings['PRODUCT'], 2, 4)]
|
||||||
|
|
||||||
|
|
||||||
def test_match_multi(matcher):
|
def test_match_multi(matcher):
|
||||||
doc = Doc(matcher.vocab, 'I like Google Now and java best'.split())
|
doc = Doc(matcher.vocab, words='I like Google Now and java best'.split())
|
||||||
assert matcher(doc) == [(doc.vocab.strings['GoogleNow'],
|
assert matcher(doc) == [(doc.vocab.strings['GoogleNow'],
|
||||||
doc.vocab.strings['PRODUCT'], 2, 4),
|
doc.vocab.strings['PRODUCT'], 2, 4),
|
||||||
(doc.vocab.strings['Java'],
|
(doc.vocab.strings['Java'],
|
||||||
|
@ -61,9 +61,9 @@ def test_match_zero(matcher):
|
||||||
{'OP': '!', 'IS_PUNCT': True},
|
{'OP': '!', 'IS_PUNCT': True},
|
||||||
{'ORTH': '"'}
|
{'ORTH': '"'}
|
||||||
]])
|
]])
|
||||||
doc = Doc(matcher.vocab, 'He said , " some words " ...'.split())
|
doc = Doc(matcher.vocab, words='He said , " some words " ...'.split())
|
||||||
assert len(matcher(doc)) == 1
|
assert len(matcher(doc)) == 1
|
||||||
doc = Doc(matcher.vocab, 'He said , " some three words " ...'.split())
|
doc = Doc(matcher.vocab, words='He said , " some three words " ...'.split())
|
||||||
assert len(matcher(doc)) == 0
|
assert len(matcher(doc)) == 0
|
||||||
matcher.add('Quote', '', {}, [
|
matcher.add('Quote', '', {}, [
|
||||||
[
|
[
|
||||||
|
@ -83,24 +83,24 @@ def test_match_zero_plus(matcher):
|
||||||
{'OP': '*', 'IS_PUNCT': False},
|
{'OP': '*', 'IS_PUNCT': False},
|
||||||
{'ORTH': '"'}
|
{'ORTH': '"'}
|
||||||
]])
|
]])
|
||||||
doc = Doc(matcher.vocab, 'He said , " some words " ...'.split())
|
doc = Doc(matcher.vocab, words='He said , " some words " ...'.split())
|
||||||
assert len(matcher(doc)) == 1
|
assert len(matcher(doc)) == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.models
|
#@pytest.mark.models
|
||||||
def test_match_preserved(EN):
|
#def test_match_preserved(EN):
|
||||||
patterns = {
|
# patterns = {
|
||||||
'JS': ['PRODUCT', {}, [[{'ORTH': 'JavaScript'}]]],
|
# 'JS': ['PRODUCT', {}, [[{'ORTH': 'JavaScript'}]]],
|
||||||
'GoogleNow': ['PRODUCT', {}, [[{'ORTH': 'Google'}, {'ORTH': 'Now'}]]],
|
# 'GoogleNow': ['PRODUCT', {}, [[{'ORTH': 'Google'}, {'ORTH': 'Now'}]]],
|
||||||
'Java': ['PRODUCT', {}, [[{'LOWER': 'java'}]]],
|
# 'Java': ['PRODUCT', {}, [[{'LOWER': 'java'}]]],
|
||||||
}
|
# }
|
||||||
matcher = Matcher(EN.vocab, patterns)
|
# matcher = Matcher(EN.vocab, patterns)
|
||||||
doc = EN.tokenizer('I like java.')
|
# doc = EN.tokenizer('I like java.')
|
||||||
EN.tagger(doc)
|
# EN.tagger(doc)
|
||||||
assert len(doc.ents) == 0
|
# assert len(doc.ents) == 0
|
||||||
doc = EN.tokenizer('I like java.')
|
# doc = EN.tokenizer('I like java.')
|
||||||
doc.ents += tuple(matcher(doc))
|
# doc.ents += tuple(matcher(doc))
|
||||||
assert len(doc.ents) == 1
|
# assert len(doc.ents) == 1
|
||||||
EN.tagger(doc)
|
# EN.tagger(doc)
|
||||||
EN.entity(doc)
|
# EN.entity(doc)
|
||||||
assert len(doc.ents) == 1
|
# assert len(doc.ents) == 1
|
||||||
|
|
|
@ -9,7 +9,7 @@ def nlp():
|
||||||
if os.environ.get('SPACY_DATA'):
|
if os.environ.get('SPACY_DATA'):
|
||||||
data_dir = os.environ.get('SPACY_DATA')
|
data_dir = os.environ.get('SPACY_DATA')
|
||||||
else:
|
else:
|
||||||
data_dir = None
|
data_dir = True
|
||||||
return English(path=data_dir)
|
return English(path=data_dir)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user