| 42 | } |
| 43 | |
| 44 | std::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 | |
| 72 | py::UniqueCObj<DocumentObject> MGLDAModelObject::makeDoc(PyObject* words, const std::string& delimiter) |
| 73 | { |
nothing calls this directly
no test coverage detected