| 43 | } |
| 44 | |
| 45 | std::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 | |
| 73 | py::UniqueCObj<DocumentObject> DTModelObject::makeDoc(PyObject* words, size_t timepoint) |
| 74 | { |
nothing calls this directly
no test coverage detected