mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 09:56:28 +03:00
Add .blank() method to Parser. Start housing default dep labels and entity types within the Defaults class.
This commit is contained in:
parent
722199acb8
commit
2debc4e0a2
|
@ -29,6 +29,7 @@ from . import util
|
|||
from .lemmatizer import Lemmatizer
|
||||
|
||||
from .attrs import TAG, DEP, ENT_IOB, ENT_TYPE, HEAD, PROB, LANG, IS_STOP
|
||||
from .syntax.parser import get_templates
|
||||
|
||||
|
||||
class BaseDefaults(object):
|
||||
|
@ -98,14 +99,14 @@ class BaseDefaults(object):
|
|||
return Parser.load(self.path / 'deps', vocab, ArcEager)
|
||||
else:
|
||||
return Parser.blank(vocab, ArcEager,
|
||||
Parser.default_templates('%s-parser' % self.lang))
|
||||
features=self.parser_features, labels=self.parser_labels)
|
||||
|
||||
def Entity(self, vocab):
|
||||
if self.path and (self.path / 'ner').exists():
|
||||
return Parser.load(self.path / 'ner', vocab, BiluoPushDown)
|
||||
else:
|
||||
return Parser.blank(vocab, BiluoPushdown,
|
||||
Parser.default_templates('%s-entity' % self.lang))
|
||||
features=self.entity_features, labels=self.entity_labels)
|
||||
|
||||
def Matcher(self, vocab):
|
||||
if self.path:
|
||||
|
@ -120,9 +121,13 @@ class BaseDefaults(object):
|
|||
nlp.parser,
|
||||
nlp.entity]
|
||||
|
||||
dep_labels = {0: {'ROOT': True}}
|
||||
parser_labels = {0: {'ROOT': True}}
|
||||
|
||||
ner_labels = {0: {'PER': True, 'LOC': True, 'ORG': True, 'MISC': True}}
|
||||
entity_labels = {0: {'PER': True, 'LOC': True, 'ORG': True, 'MISC': True}}
|
||||
|
||||
parser_features = get_templates('parser')
|
||||
|
||||
entity_features = get_templates('ner')
|
||||
|
||||
stop_words = set()
|
||||
|
||||
|
|
|
@ -89,6 +89,14 @@ cdef class Parser:
|
|||
model.load(str(path / 'model'))
|
||||
return cls(vocab, moves, model, **cfg)
|
||||
|
||||
@classmethod
|
||||
def blank(cls, Vocab vocab, moves_class, **cfg):
|
||||
moves = moves_class(vocab.strings, cfg.get('labels', {}))
|
||||
templates = get_templates(cfg.get('features', tuple()))
|
||||
model = ParserModel(templates)
|
||||
return cls(vocab, moves, model, **cfg)
|
||||
|
||||
|
||||
def __init__(self, Vocab vocab, transition_system, ParserModel model, **cfg):
|
||||
self.moves = transition_system
|
||||
self.model = model
|
||||
|
|
|
@ -3,6 +3,7 @@ import os
|
|||
|
||||
import spacy
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def EN():
|
||||
return spacy.load("en")
|
||||
|
@ -21,7 +22,6 @@ def pytest_addoption(parser):
|
|||
help="include slow tests")
|
||||
|
||||
|
||||
|
||||
def pytest_runtest_setup(item):
|
||||
for opt in ['models', 'vectors', 'slow']:
|
||||
if opt in item.keywords and not item.config.getoption("--%s" % opt):
|
||||
|
|
Loading…
Reference in New Issue
Block a user