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

Function stem

pattern/vector/stemmer.py:314–343  ·  view source on GitHub ↗

Returns the stem of the given word: ponies => poni. Note: it is often taken to be a crude error that a stemming algorithm does not leave a real word after removing the stem. But the purpose of stemming is to bring variant forms of a word together, not to map a wor

(word, cached=True, history=10000, **kwargs)

Source from the content-addressed store, hash-verified

312cache = {}
313
314def stem(word, cached=True, history=10000, **kwargs):
315 """ Returns the stem of the given word: ponies => poni.
316 Note: it is often taken to be a crude error
317 that a stemming algorithm does not leave a real word after removing the stem.
318 But the purpose of stemming is to bring variant forms of a word together,
319 not to map a word onto its "paradigm" form.
320 """
321 stem = word.lower()
322 if cached and stem in cache:
323 return case_sensitive(cache[stem], word)
324 if cached and len(cache) > history: # Empty cache every now and then.
325 cache.clear()
326 if len(stem) <= 2:
327 # If the word has two letters or less, leave it as it is.
328 return case_sensitive(stem, word)
329 if stem in exceptions:
330 return case_sensitive(exceptions[stem], word)
331 if stem in uninflected:
332 return case_sensitive(stem, word)
333 # Mark y treated as a consonant as Y.
334 stem = upper_consonant_y(stem)
335 for f in (step_1a, step_1b, step_1c, step_2, step_3, step_4, step_5a, step_5b):
336 stem = f(stem)
337 # Turn any remaining Y letters in the stem back into lower case.
338 # Apply the case of the original word to the stem.
339 stem = stem.lower()
340 stem = case_sensitive(stem, word)
341 if cached:
342 cache[word.lower()] = stem.lower()
343 return stem

Callers

nothing calls this directly

Calls 5

case_sensitiveFunction · 0.85
lenFunction · 0.85
upper_consonant_yFunction · 0.85
fFunction · 0.85
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…