MCPcopy Create free account
hub / github.com/bab2min/tomotopy / addDoc

Method addDoc

src/python/handler/py_DT.cpp:45–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45std::optional<size_t> DTModelObject::addDoc(PyObject* words, size_t timepoint, bool ignoreEmptyWords)
46{
47 if (isPrepared) throw py::RuntimeError{ "cannot add_doc() after train()" };
48 auto* inst = getInst<tomoto::IDTModel>();
49 if (PyUnicode_Check(words))
50 {
51 if (PyErr_WarnEx(PyExc_RuntimeWarning, "`words` should be an iterable of str.", 1)) throw py::ExcPropagation{};
52 }
53 tomoto::RawDoc raw = buildRawDoc(words);
54 raw.misc["timepoint"] = (uint32_t)timepoint;
55 try
56 {
57 auto ret = inst->addDoc(raw);
58 return py::buildPyValue(ret);
59 }
60 catch (const tomoto::exc::EmptyWordArgument&)
61 {
62 if (ignoreEmptyWords)
63 {
64 return std::nullopt;
65 }
66 else
67 {
68 throw;
69 }
70 }
71}
72
73py::UniqueCObj<DocumentObject> DTModelObject::makeDoc(PyObject* words, size_t timepoint)
74{

Callers

nothing calls this directly

Calls 2

buildRawDocFunction · 0.85
buildPyValueFunction · 0.70

Tested by

no test coverage detected