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

Method train

pattern/text/__init__.py:1732–1743  ·  view source on GitHub ↗

Counts the words in the given string and saves the probabilities at the given path. This can be used to generate a new model for the Spelling() constructor.

(self, s, path="spelling.txt")

Source from the content-addressed store, hash-verified

1730
1731 @classmethod
1732 def train(self, s, path="spelling.txt"):
1733 """ Counts the words in the given string and saves the probabilities at the given path.
1734 This can be used to generate a new model for the Spelling() constructor.
1735 """
1736 model = {}
1737 for w in re.findall("[a-z]+", s.lower()):
1738 model[w] = w in model and model[w] + 1 or 1
1739 model = ("%s %s" % (k, v) for k, v in sorted(model.items()))
1740 model = "\n".join(model)
1741 f = open(path, "w")
1742 f.write(model)
1743 f.close()
1744
1745 def _edit1(self, w):
1746 """ Returns a set of words with edit distance 1 from the given word.

Callers

nothing calls this directly

Calls 3

writeMethod · 0.80
itemsMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected