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

Method save

pattern/vector/__init__.py:420–452  ·  view source on GitHub ↗

Saves the document as a text file at the given path. The file content has the following format: # Cat document. @name: cat @type: animal a 3 cat 2 catch 1 claw 1 ...

(self, path)

Source from the content-addressed store, hash-verified

418 description = a.get("description").rstrip("\n"))
419
420 def save(self, path):
421 """ Saves the document as a text file at the given path.
422 The file content has the following format:
423 # Cat document.
424 @name: cat
425 @type: animal
426 a 3
427 cat 2
428 catch 1
429 claw 1
430 ...
431 """
432 s = []
433 # Parse document description.
434 for x in self.description.split("\n"):
435 s.append("# %s" % x)
436 # Parse document name, type and language.
437 for k, v in (("@name:", self.name), ("@type:", self.type), ("@lang:", self.language)):
438 if v is not None:
439 s.append("%s %s" % (k, v.replace("\n", "\\n")))
440 # Parse document terms and frequency.
441 for w, f in sorted(self.terms.items()):
442 if isinstance(f, int):
443 s.append("%s %i" % (w, f))
444 if isinstance(f, float):
445 s.append("%s %.3f" % (w, f))
446 s = "\n".join(s)
447 s = encode_utf8(s)
448 # Save unicode file.
449 f = open(path, "wb")
450 f.write(codecs.BOM_UTF8)
451 f.write(s)
452 f.close()
453
454 def _get_model(self):
455 return self._model

Callers 1

test_document_loadMethod · 0.95

Calls 6

encode_utf8Function · 0.85
writeMethod · 0.80
splitMethod · 0.45
appendMethod · 0.45
itemsMethod · 0.45
closeMethod · 0.45

Tested by 1

test_document_loadMethod · 0.76