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

Method makeDoc

src/python/handler/py_LLDA.cpp:86–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86py::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
118py::UniqueCObj<VocabObject> LLDAModelObject::getTopicLabelDict() const
119{

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