mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 00:46:28 +03:00
Add more docstrings for MorphAnalysis
This commit is contained in:
parent
ff51fba96a
commit
7d782aa97b
|
@ -20,6 +20,7 @@ cdef class MorphAnalysis:
|
|||
|
||||
@classmethod
|
||||
def from_id(cls, Vocab vocab, hash_t key):
|
||||
"""Create a morphological analysis from a given ID."""
|
||||
cdef MorphAnalysis morph = MorphAnalysis.__new__(MorphAnalysis, vocab)
|
||||
morph.vocab = vocab
|
||||
morph.key = key
|
||||
|
@ -31,15 +32,18 @@ cdef class MorphAnalysis:
|
|||
return morph
|
||||
|
||||
def __contains__(self, feature):
|
||||
"""Test whether the morphological analysis contains some feature."""
|
||||
cdef attr_t feat_id = get_string_id(feature)
|
||||
return check_feature(&self.c, feat_id)
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over the features in the analysis."""
|
||||
cdef attr_t feature
|
||||
for feature in list_features(&self.c):
|
||||
yield self.vocab.strings[feature]
|
||||
|
||||
def __len__(self):
|
||||
"""The number of features in the analysis."""
|
||||
return self.c.length
|
||||
|
||||
def __str__(self):
|
||||
|
@ -52,10 +56,14 @@ cdef class MorphAnalysis:
|
|||
return self.key
|
||||
|
||||
def get(self, unicode field):
|
||||
"""Retrieve a feature by field."""
|
||||
cdef int field_id = self.vocab.morphology._feat_map.attr2field[field]
|
||||
return self.vocab.strings[get_field(&self.c, field_id)]
|
||||
|
||||
def to_json(self):
|
||||
"""Produce a json serializable representation, which will be a list of
|
||||
strings.
|
||||
"""
|
||||
return tag_to_json(&self.c)
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue
Block a user