def do_form(self, lemma, categories, words = ()): """ Generate the specified inflected form for the lemma, preserving the given words. When a word form is provided, it is returned; when not, it is generated applying the appropriate inflection form. @param lemma: The lemma to inflect. @type lemma: Lemma @param categories: The categories of the word to generate. @type categories: tuple of str/CategoryFilter @param words: The inflected forms (usually a list of irregular forms). @type words: sequence of Word @return: The inflected word form for the lemma. @rtype: Word @raise InflectionError: If the inflection form can not accept the lemma respecting mandatory steps. @raise TransformSyntaxError: If the substitution pattern in some step can not be compiled. """ word = None #Find is there is a default form for w in words: if CategoryFilter.test(categories, w.categories): word = w break if word is None: #Get the form == dict of transforms form = self.__forms[categories] s = None #Iterate over transforms for transform in form: s = transform(lemma, words) if s is not None: break if s is None: raise InflectionError("Inflection can not generate %s for lemma '%s'" % (Utilities.tuple_str(categories), `lemma`)) word = Word(s, lemma, categories) return word
def __repr__(self): """ Return a verbose string representation. @rtype: str """ p_o_s, lemma_categories, categories = self._content[3:6] r = [] r.append("{") if p_o_s: r.append(p_o_s) else: r.append("*") if lemma_categories: r.append(Utilities.tuple_str(lemma_categories)) elif categories: r.append("()") if categories: r.append(Utilities.tuple_str(categories)) r.append("}") return "".join(r)
def __repr__(self): """ Give a verbose representation for a word in the format <form>@<lemma><categories>, for example: [email protected]('pl',)" @rtype: str """ z = Utilities.unidecode(self.__form) + "@" + ` self.__lemma ` if len(self.categories) == 0: return z else: return z + Utilities.tuple_str(self.categories)
def __str__(self): """ Return a short string representation. @rtype: str """ s = [self.p_o_s] if self.condition: s.append(self.condition) if self.lemma_categories: s.append(Utilities.tuple_str(self.lemma_categories)) return " ".join(s)