MCPcopy Create free account
hub / github.com/bab2min/tomotopy / makeDoc

Method makeDoc

src/python/handler/py_PLDA.cpp:85–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85py::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
117py::UniqueCObj<VocabObject> PLDAModelObject::getTopicLabelDict() const
118{

Callers

nothing calls this directly

Calls 5

buildRawDocFunction · 0.85
toCppFunction · 0.85
getDocumentClsFunction · 0.85
copyMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected