| 84 | } |
| 85 | |
| 86 | py::UniqueCObj<DocumentObject> LLDAModelObject::makeDoc(PyObject* words, PyObject* labels) |
| 87 | { |
| 88 | if (!isPrepared) throw py::RuntimeError{ "`train()` should be called before `make_doc()`." }; |
| 89 | auto* inst = getInst<tomoto::ILLDAModel>(); |
| 90 | if (PyUnicode_Check(words)) |
| 91 | { |
| 92 | if (PyErr_WarnEx(PyExc_RuntimeWarning, "`words` should be an iterable of str.", 1)) throw py::ExcPropagation{}; |
| 93 | } |
| 94 | tomoto::RawDoc raw = buildRawDoc(words); |
| 95 | |
| 96 | if (labels) |
| 97 | { |
| 98 | if (PyUnicode_Check(labels)) |
| 99 | { |
| 100 | if (PyErr_WarnEx(PyExc_RuntimeWarning, "`labels` should be an iterable of str.", 1)) throw py::ExcPropagation{}; |
| 101 | } |
| 102 | vector<string> labelVec; |
| 103 | if (!py::toCpp(labels, labelVec)) |
| 104 | { |
| 105 | throw py::ValueError{ "`labels` must be an iterable of str." }; |
| 106 | } |
| 107 | raw.misc["labels"] = labelVec; |
| 108 | } |
| 109 | auto doc = inst->makeDoc(raw); |
| 110 | py::UniqueCObj<CorpusObject> corpus{ (CorpusObject*)PyObject_CallFunctionObjArgs((PyObject*)py::Type<CorpusObject>, Py_None, getObject(), nullptr) }; |
| 111 | auto ret = py::makeNewObject<DocumentObject>(getDocumentCls()); |
| 112 | ret->corpus = corpus.copy(); |
| 113 | ret->doc = doc.release(); |
| 114 | ret->owner = true; |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | py::UniqueCObj<VocabObject> LLDAModelObject::getTopicLabelDict() const |
| 119 | { |
nothing calls this directly
no test coverage detected