MCPcopy Index your code
hub / github.com/clips/pattern / stem

Function stem

pattern/vector/__init__.py:215–243  ·  view source on GitHub ↗

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(). (with optional parameter language="en", pattern.en.inflect is used).

(word, stemmer=PORTER, **kwargs)

Source from the content-addressed store, hash-verified

213
214PORTER, LEMMA = "porter", "lemma"
215def stem(word, stemmer=PORTER, **kwargs):
216 """ Returns the base form of the word when counting words in count().
217 With stemmer=PORTER, the Porter2 stemming algorithm is used.
218 With stemmer=LEMMA, either uses Word.lemma or inflect.singularize().
219 (with optional parameter language="en", pattern.en.inflect is used).
220 """
221 if isinstance(word, basestring):
222 word = decode_utf8(word.lower())
223 if stemmer is None:
224 return word.lower()
225 if stemmer == PORTER:
226 return _stemmer.stem(word, **kwargs)
227 if stemmer == LEMMA:
228 if word.__class__.__name__ == "Word":
229 w = word.string.lower()
230 if word.lemma is not None:
231 return word.lemma
232 if word.pos == "NNS":
233 return singularize(w)
234 if word.pos.startswith(("VB", "MD")):
235 return conjugate(w, "infinitive") or w
236 if word.pos.startswith(("JJ",)):
237 return predicative(w)
238 if word.pos.startswith(("DT", "PR", "WP")):
239 return singularize(w, pos=pos)
240 return singularize(word, pos=kwargs.get("pos", "noun"))
241 if hasattr(stemmer, "__call__"):
242 return decode_utf8(stemmer(word))
243 return word.lower()
244
245def count(words=[], top=None, threshold=0, stemmer=None, exclude=[], stopwords=False, language=None, **kwargs):
246 """ Returns a dictionary of (word, count)-items, in lowercase.

Callers 1

countFunction · 0.70

Calls 5

singularizeFunction · 0.90
conjugateFunction · 0.90
predicativeFunction · 0.90
decode_utf8Function · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…