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

Method addDoc

src/python/handler/py_SLDA.cpp:106–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106std::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
143py::UniqueCObj<DocumentObject> SLDAModelObject::makeDoc(PyObject* words, PyObject* y)
144{

Callers

nothing calls this directly

Calls 3

buildRawDocFunction · 0.85
toCppFunction · 0.85
buildPyValueFunction · 0.70

Tested by

no test coverage detected