コード例 #1
0
def stem(word, stemmer=PORTER, **kwargs):
    """ Returns the base form of the word when counting words in count().
        With stemmer=PORTER, the Porter2 stemming algorithm is used.
        With stemmer=LEMMA, either uses Word.lemma or inflect.singularize().
    """
    if stemmer == PORTER:
        return _stemmer.stem(decode_utf8(word).lower(), **kwargs)
    if stemmer == LEMMA:
        if word.__class__.__name__ == "Word":
            if word.lemma is not None:
                return word.lemma
            if word.pos == "NNS":
                return singularize(word.string.lower())
            if word.pos.startswith("VB"):
                return conjugate(word.string.lower(), "infinitive") or word
        return singularize(word)
    return word
コード例 #2
0
ファイル: __init__.py プロジェクト: Dirklectisch/cityment
def stem(word, stemmer=PORTER, **kwargs):
    """ Returns the base form of the word when counting words in count().
        With stemmer=PORTER, the Porter2 stemming algorithm is used.
        With stemmer=LEMMA, either uses Word.lemma or inflect.singularize().
    """
    if stemmer == PORTER:
        return _stemmer.stem(decode_utf8(word).lower(), **kwargs)
    if stemmer == LEMMA:
        if word.__class__.__name__ == "Word":
            if word.lemma is not None:
                return word.lemma
            if word.pos == "NNS":
                return singularize(word.string.lower())
            if word.pos.startswith("VB"):
                return conjugate(word.string.lower(), "infinitive") or word
        return singularize(word)
    return word
コード例 #3
0
ファイル: __init__.py プロジェクト: agermanidis/Pattern
def lemma(word, pos="NN"):
    """ Returns the lemma of the given word, e.g. horses/NNS => horse, am/VBP => be.
        Words must be lowercase.
    """
    if pos == "NNS":
        return singularize(word)
    if pos.startswith("VB"):
        return conjugate(word, "infinitive") or word
    return word