| 44 | } |
| 45 | |
| 46 | std::optional<size_t> LLDAModelObject::addDoc(PyObject* words, PyObject* labels, bool ignoreEmptyWords) |
| 47 | { |
| 48 | if (isPrepared) throw py::RuntimeError{ "cannot add_doc() after train()" }; |
| 49 | auto* inst = getInst<tomoto::ILLDAModel>(); |
| 50 | if (PyUnicode_Check(words)) |
| 51 | { |
| 52 | if (PyErr_WarnEx(PyExc_RuntimeWarning, "`words` should be an iterable of str.", 1)) throw py::ExcPropagation{}; |
| 53 | } |
| 54 | tomoto::RawDoc raw = buildRawDoc(words); |
| 55 | if (labels) |
| 56 | { |
| 57 | if (PyUnicode_Check(labels)) |
| 58 | { |
| 59 | if (PyErr_WarnEx(PyExc_RuntimeWarning, "`labels` should be an iterable of str.", 1)) throw py::ExcPropagation{}; |
| 60 | } |
| 61 | vector<string> labelVec; |
| 62 | if (!py::toCpp(labels, labelVec)) |
| 63 | { |
| 64 | throw py::ValueError{ "`labels` must be an iterable of str." }; |
| 65 | } |
| 66 | raw.misc["labels"] = labelVec; |
| 67 | } |
| 68 | try |
| 69 | { |
| 70 | auto ret = inst->addDoc(raw); |
| 71 | return py::buildPyValue(ret); |
| 72 | } |
| 73 | catch (const tomoto::exc::EmptyWordArgument&) |
| 74 | { |
| 75 | if (ignoreEmptyWords) |
| 76 | { |
| 77 | return std::nullopt; |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | throw; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | py::UniqueCObj<DocumentObject> LLDAModelObject::makeDoc(PyObject* words, PyObject* labels) |
| 87 | { |
nothing calls this directly
no test coverage detected