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

Method addDoc

src/python/handler/py_MGLDA.cpp:44–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

buildRawDocFunction · 0.85
buildPyValueFunction · 0.70

Tested by

no test coverage detected