From 7d782aa97b6a027a574bef491cb50cd3c3e2707d Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 12 Sep 2019 16:48:10 +0200 Subject: [PATCH] Add more docstrings for MorphAnalysis --- spacy/tokens/morphanalysis.pyx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spacy/tokens/morphanalysis.pyx b/spacy/tokens/morphanalysis.pyx index 17b11d84f..e09870741 100644 --- a/spacy/tokens/morphanalysis.pyx +++ b/spacy/tokens/morphanalysis.pyx @@ -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