Work on morphanalysis class

This commit is contained in:
Matthew Honnibal 2019-03-07 18:32:51 +01:00
parent 2669190b85
commit 357066ee2f

View File

@ -1,5 +1,10 @@
from libc.string cimport memset
from ..vocab cimport Vocab from ..vocab cimport Vocab
from ..typedefs cimport hash_t from ..typedefs cimport hash_t, attr_t
from ..morphology cimport check_feature, tag_to_json
from ..strings import get_string_id
cdef class MorphAnalysis: cdef class MorphAnalysis:
@ -8,223 +13,234 @@ cdef class MorphAnalysis:
self.vocab = vocab self.vocab = vocab
self.key = self.vocab.morphology.add(features) self.key = self.vocab.morphology.add(features)
analysis = <const MorphAnalysisC*>self.vocab.morphology.tags.get(self.key) analysis = <const MorphAnalysisC*>self.vocab.morphology.tags.get(self.key)
self.c = analysis[0] if analysis is not NULL:
self.c = analysis[0]
else:
memset(&self.c, 0, sizeof(self.c))
@classmethod @classmethod
def from_id(self, Vocab vocab, hash_t key): def from_id(cls, Vocab vocab, hash_t key):
pass cdef MorphAnalysis morph = MorphAnalysis.__new__(MorphAnalysis, vocab)
morph.key = key
analysis = <const MorphAnalysisC*>vocab.morphology.tags.get(key)
if analysis is not NULL:
morph.c = analysis[0]
else:
memset(&morph.c, 0, sizeof(morph.c))
return morph
def __contains__(self, feature): def __contains__(self, feature):
pass cdef attr_t feat_id = get_string_id(feature)
return check_feature(&self.c, feat_id)
def __iter__(self): def __iter__(self):
pass raise NotImplementedError
def __len__(self): def __len__(self):
pass raise NotImplementedError
def __str__(self): def __str__(self):
pass raise NotImplementedError
def __repr__(self): def __repr__(self):
pass raise NotImplementedError
def __hash__(self): def __hash__(self):
pass raise NotImplementedError
def get(self, name): def get(self, field):
pass raise NotImplementedError
def to_json(self): def to_json(self):
pass return tag_to_json(self.c)
@property @property
def is_base_form(self): def is_base_form(self):
pass raise NotImplementedError
@property @property
def pos(self): def pos(self):
pass return self.c.pos
@property @property
def pos_(self): def pos_(self):
pass return self.vocab.strings[self.c.pos]
@property property id:
def id(self): def __get__(self):
pass return self.key
property abbr: property abbr:
def __get__(self): def __get__(self):
pass return self.c.abbr
property adp_type: property adp_type:
def __get__(self): def __get__(self):
pass return self.c.adp_type
property adv_type: property adv_type:
def __get__(self): def __get__(self):
pass return self.c.adv_type
property animacy: property animacy:
def __get__(self): def __get__(self):
pass return self.c.animacy
property aspect: property aspect:
def __get__(self): def __get__(self):
pass return self.c.aspect
property case: property case:
def __get__(self): def __get__(self):
pass return self.c.case
property conj_type: property conj_type:
def __get__(self): def __get__(self):
pass return self.c.conj_type
property connegative: property connegative:
def __get__(self): def __get__(self):
pass return self.c.connegative
property definite: property definite:
def __get__(self): def __get__(self):
pass return self.c.definite
property degree: property degree:
def __get__(self): def __get__(self):
pass return self.c.degree
property derivation: property derivation:
def __get__(self): def __get__(self):
pass return self.c.derivation
property echo: property echo:
def __get__(self): def __get__(self):
pass return self.c.echo
property foreign: property foreign:
def __get__(self): def __get__(self):
pass return self.c.foreign
property gender: property gender:
def __get__(self): def __get__(self):
pass return self.c.gender
property hyph: property hyph:
def __get__(self): def __get__(self):
pass return self.c.hyph
property inf_form: property inf_form:
def __get__(self): def __get__(self):
pass return self.c.inf_form
property mood: property mood:
def __get__(self): def __get__(self):
pass return self.c.mood
property name_type: property name_type:
def __get__(self): def __get__(self):
pass return self.c.name_type
property negative: property negative:
def __get__(self): def __get__(self):
pass return self.c.negative
property noun_type: property noun_type:
def __get__(self): def __get__(self):
pass return self.c.noun_type
property number: property number:
def __get__(self): def __get__(self):
pass return self.c.number
property num_form: property num_form:
def __get__(self): def __get__(self):
pass return self.c.num_form
property num_type: property num_type:
def __get__(self): def __get__(self):
pass return self.c.num_type
property num_value: property num_value:
def __get__(self): def __get__(self):
pass return self.c.num_value
property part_form: property part_form:
def __get__(self): def __get__(self):
pass return self.c.part_form
property part_type: property part_type:
def __get__(self): def __get__(self):
pass return self.c.part_type
property person: property person:
def __get__(self): def __get__(self):
pass return self.c.person
property polite: property polite:
def __get__(self): def __get__(self):
pass return self.c.polite
property polarity: property polarity:
def __get__(self): def __get__(self):
pass return self.c.polarity
property poss: property poss:
def __get__(self): def __get__(self):
pass return self.c.poss
property prefix: property prefix:
def __get__(self): def __get__(self):
pass return self.c.prefix
property prep_case: property prep_case:
def __get__(self): def __get__(self):
pass return self.c.prep_case
property pron_type: property pron_type:
def __get__(self): def __get__(self):
pass return self.c.pron_type
property punct_side: property punct_side:
def __get__(self): def __get__(self):
pass return self.c.punct_side
property punct_type: property punct_type:
def __get__(self): def __get__(self):
pass return self.c.punct_type
property reflex: property reflex:
def __get__(self): def __get__(self):
pass return self.c.reflex
property style: property style:
def __get__(self): def __get__(self):
pass return self.c.style
property style_variant: property style_variant:
def __get__(self): def __get__(self):
pass return self.c.style_variant
property tense: property tense:
def __get__(self): def __get__(self):
pass return self.c.tense
property typo: property typo:
def __get__(self): def __get__(self):
pass return self.c.typo
property verb_form: property verb_form:
def __get__(self): def __get__(self):
pass return self.c.verb_form
property voice: property voice:
def __get__(self): def __get__(self):
pass return self.c.voice
property verb_type: property verb_type:
def __get__(self): def __get__(self):
pass return self.c.verb_type
property abbr_: property abbr_:
def __get__(self): def __get__(self):