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

Method save

pattern/vector/__init__.py:827–842  ·  view source on GitHub ↗

Saves the model as a pickle file at the given path. The advantage is that cached vectors and cosine similarity are stored.

(self, path, update=False)

Source from the content-addressed store, hash-verified

825 return cPickle.load(open(path))
826
827 def save(self, path, update=False):
828 """ Saves the model as a pickle file at the given path.
829 The advantage is that cached vectors and cosine similarity are stored.
830 """
831 if update:
832 # Update the entire cache before saving.
833 for d1 in self.documents:
834 for d2 in self.documents:
835 self.cosine_similarity(d1, d2)
836 m = dict.fromkeys((d.id for d in self.documents), True)
837 for id1, id2 in self._cos.keys():
838 # Remove Model.search() query cache.
839 if id1 not in m \
840 or id2 not in m:
841 self._cos.pop((id1, id2))
842 cPickle.dump(self, open(path, "wb"), 1) # 1 = binary
843
844 def export(self, path, format=ORANGE, **kwargs):
845 """ Exports the model as a file for other machine learning applications,

Callers

nothing calls this directly

Calls 5

cosine_similarityMethod · 0.95
fromkeysMethod · 0.45
keysMethod · 0.45
popMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected