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