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

Method CoherenceObject

src/python/handler/py_coherence.cpp:7–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5using namespace std;
6
7CoherenceObject::CoherenceObject(PyObject* corpus,
8 ProbEstimation pe, Segmentation seg, ConfirmMeasure cm, IndirectMeasure im,
9 size_t windowSize, double eps, double gamma, PyObject* targets)
10 : model{ pe, windowSize }
11{
12 this->corpus = py::checkType<CorpusObject>(py::UniqueObj{ corpus }, "`corpus` must be an instance of `tomotopy.utils.Corpus`.");
13 this->corpus.incref();
14
15 vector<tomoto::Vid> targetIds;
16 py::foreach<string>(targets, [&](const string& w)
17 {
18 auto wid = this->corpus->getVocabDict().toWid(w);
19 if (wid != tomoto::non_vocab_id) targetIds.emplace_back(wid);
20 }, "`targets` must be an iterable of `str`.");
21
22 this->model.insertTargets(targetIds.begin(), targetIds.end());
23
24 for (size_t i = 0; i < this->corpus->len(); ++i)
25 {
26 auto* doc = this->corpus->getDoc(i);
27 this->model.insertDoc(
28 wordBegin(doc, this->corpus->isIndependent()),
29 wordEnd(doc, this->corpus->isIndependent())
30 );
31 }
32
33 this->seg = seg;
34 this->cm = tomoto::coherence::AnyConfirmMeasurer::getInstance(cm, im, targetIds.begin(), targetIds.end(), eps, gamma);
35}
36
37double CoherenceObject::getScore(PyObject* words) const
38{

Callers

nothing calls this directly

Calls 12

wordBeginFunction · 0.85
wordEndFunction · 0.85
toWidMethod · 0.80
emplace_backMethod · 0.80
isIndependentMethod · 0.80
increfMethod · 0.45
insertTargetsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
lenMethod · 0.45
getDocMethod · 0.45
insertDocMethod · 0.45

Tested by

no test coverage detected