| 104 | } |
| 105 | |
| 106 | std::optional<size_t> SLDAModelObject::addDoc(PyObject* words, PyObject* y, bool ignoreEmptyWords) |
| 107 | { |
| 108 | if (isPrepared) throw py::RuntimeError{ "cannot add_doc() after train()" }; |
| 109 | auto* inst = getInst<tomoto::ISLDAModel>(); |
| 110 | if (PyUnicode_Check(words)) |
| 111 | { |
| 112 | if (PyErr_WarnEx(PyExc_RuntimeWarning, "`words` should be an iterable of str.", 1)) throw py::ExcPropagation{}; |
| 113 | } |
| 114 | tomoto::RawDoc raw = buildRawDoc(words); |
| 115 | |
| 116 | if (y) |
| 117 | { |
| 118 | vector<tomoto::Float> yVec; |
| 119 | if (!py::toCpp(y, yVec)) |
| 120 | { |
| 121 | throw py::ValueError{ "`y` must be an iterable of float." }; |
| 122 | } |
| 123 | raw.misc["y"] = yVec; |
| 124 | } |
| 125 | try |
| 126 | { |
| 127 | auto ret = inst->addDoc(raw); |
| 128 | return py::buildPyValue(ret); |
| 129 | } |
| 130 | catch (const tomoto::exc::EmptyWordArgument&) |
| 131 | { |
| 132 | if (ignoreEmptyWords) |
| 133 | { |
| 134 | return std::nullopt; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | throw; |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | py::UniqueCObj<DocumentObject> SLDAModelObject::makeDoc(PyObject* words, PyObject* y) |
| 144 | { |
nothing calls this directly
no test coverage detected