2016-10-16 02:47:12 +03:00
|
|
|
from .syntax.parser cimport Parser
|
2017-03-11 16:00:20 +03:00
|
|
|
from .syntax.beam_parser cimport BeamParser
|
2016-10-16 02:47:12 +03:00
|
|
|
from .syntax.ner cimport BiluoPushDown
|
|
|
|
from .syntax.arc_eager cimport ArcEager
|
2016-10-16 22:34:57 +03:00
|
|
|
from .tagger import Tagger
|
2016-10-16 02:47:12 +03:00
|
|
|
|
2016-10-16 22:34:57 +03:00
|
|
|
# TODO: The disorganization here is pretty embarrassing. At least it's only
|
|
|
|
# internals.
|
|
|
|
from .syntax.parser import get_templates as get_feature_templates
|
2016-10-23 18:45:44 +03:00
|
|
|
from .attrs import DEP, ENT_TYPE
|
2016-10-16 02:47:12 +03:00
|
|
|
|
|
|
|
|
2017-03-11 21:45:37 +03:00
|
|
|
cdef class EntityRecognizer(Parser):
|
2016-11-01 14:25:36 +03:00
|
|
|
"""Annotate named entities on Doc objects."""
|
2016-10-16 22:34:57 +03:00
|
|
|
TransitionSystem = BiluoPushDown
|
2017-03-11 16:00:20 +03:00
|
|
|
|
2016-10-16 22:34:57 +03:00
|
|
|
feature_templates = get_feature_templates('ner')
|
2016-10-16 02:47:12 +03:00
|
|
|
|
2016-10-23 18:45:44 +03:00
|
|
|
def add_label(self, label):
|
|
|
|
for action in self.moves.action_types:
|
|
|
|
self.moves.add_action(action, label)
|
2017-03-26 00:35:44 +03:00
|
|
|
if 'actions' in self.cfg:
|
|
|
|
self.cfg['actions'].setdefault(action,
|
|
|
|
{}).setdefault(label, True)
|
2016-10-23 18:45:44 +03:00
|
|
|
if isinstance(label, basestring):
|
|
|
|
label = self.vocab.strings[label]
|
|
|
|
for attr, freqs in self.vocab.serializer_freqs:
|
|
|
|
if attr == ENT_TYPE and label not in freqs:
|
|
|
|
freqs.append([label, 1])
|
|
|
|
# Super hacky :(
|
|
|
|
self.vocab._serializer = None
|
|
|
|
|
2016-10-16 02:47:12 +03:00
|
|
|
|
2017-03-15 17:27:41 +03:00
|
|
|
cdef class BeamEntityRecognizer(BeamParser):
|
|
|
|
"""Annotate named entities on Doc objects."""
|
|
|
|
TransitionSystem = BiluoPushDown
|
|
|
|
|
|
|
|
feature_templates = get_feature_templates('ner')
|
|
|
|
|
|
|
|
def add_label(self, label):
|
|
|
|
for action in self.moves.action_types:
|
|
|
|
self.moves.add_action(action, label)
|
2017-03-26 00:35:44 +03:00
|
|
|
if 'actions' in self.cfg:
|
|
|
|
self.cfg['actions'].setdefault(action,
|
|
|
|
{}).setdefault(label, True)
|
2017-03-15 17:27:41 +03:00
|
|
|
if isinstance(label, basestring):
|
|
|
|
label = self.vocab.strings[label]
|
|
|
|
for attr, freqs in self.vocab.serializer_freqs:
|
|
|
|
if attr == ENT_TYPE and label not in freqs:
|
|
|
|
freqs.append([label, 1])
|
|
|
|
# Super hacky :(
|
|
|
|
self.vocab._serializer = None
|
|
|
|
|
|
|
|
|
2017-03-11 20:11:30 +03:00
|
|
|
cdef class DependencyParser(Parser):
|
2016-10-16 22:34:57 +03:00
|
|
|
TransitionSystem = ArcEager
|
2016-10-16 02:47:12 +03:00
|
|
|
|
2016-10-16 22:34:57 +03:00
|
|
|
feature_templates = get_feature_templates('basic')
|
2016-10-23 18:45:44 +03:00
|
|
|
|
|
|
|
def add_label(self, label):
|
|
|
|
for action in self.moves.action_types:
|
|
|
|
self.moves.add_action(action, label)
|
2017-03-26 00:35:44 +03:00
|
|
|
if 'actions' in self.cfg:
|
|
|
|
self.cfg['actions'].setdefault(action,
|
|
|
|
{}).setdefault(label, True)
|
2016-10-23 18:45:44 +03:00
|
|
|
if isinstance(label, basestring):
|
|
|
|
label = self.vocab.strings[label]
|
|
|
|
for attr, freqs in self.vocab.serializer_freqs:
|
|
|
|
if attr == DEP and label not in freqs:
|
|
|
|
freqs.append([label, 1])
|
|
|
|
# Super hacky :(
|
|
|
|
self.vocab._serializer = None
|
|
|
|
|
2016-10-16 02:47:12 +03:00
|
|
|
|
2017-03-15 17:27:41 +03:00
|
|
|
cdef class BeamDependencyParser(BeamParser):
|
|
|
|
TransitionSystem = ArcEager
|
|
|
|
|
|
|
|
feature_templates = get_feature_templates('basic')
|
|
|
|
|
|
|
|
def add_label(self, label):
|
|
|
|
for action in self.moves.action_types:
|
|
|
|
self.moves.add_action(action, label)
|
2017-03-26 00:35:44 +03:00
|
|
|
if 'actions' in self.cfg:
|
|
|
|
self.cfg['actions'].setdefault(action,
|
|
|
|
{}).setdefault(label, True)
|
2017-03-15 17:27:41 +03:00
|
|
|
if isinstance(label, basestring):
|
|
|
|
label = self.vocab.strings[label]
|
|
|
|
for attr, freqs in self.vocab.serializer_freqs:
|
|
|
|
if attr == DEP and label not in freqs:
|
|
|
|
freqs.append([label, 1])
|
|
|
|
# Super hacky :(
|
|
|
|
self.vocab._serializer = None
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [Tagger, DependencyParser, EntityRecognizer, BeamDependencyParser, BeamEntityRecognizer]
|