IWordFormsProvider class

IWordFormsProvider class

Defines interface of a word forms provider.

Learn more

The IWordFormsProvider type exposes the following members:

Methods

Method Description
get_word_forms Gets the word forms for the specified word.

Example

class SimpleWordFormsProvider:
    def get_word_forms(self, word):
        result = []
        lower_word = word.lower()

        # Assume the input word is plural, add singular forms
        if len(word) > 3 and lower_word.endswith("ies"):
            result.append(word[:-3] + "y")
        if len(word) > 2 and lower_word.endswith("es"):
            result.append(word[:-2])
        if len(word) > 1 and lower_word.endswith("s"):
            result.append(word[:-1])

        # Assume the input word is singular, add plural forms
        if len(word) > 1 and lower_word.endswith("y"):
            result.append(word[:-1] + "ies")
        elif lower_word.endswith(("s", "x", "ch", "sh")):
            result.append(word + "es")
        else:
            result.append(word + "s")

        return result

See Also