| 5 | using namespace std; |
| 6 | |
| 7 | CoherenceObject::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 | |
| 37 | double CoherenceObject::getScore(PyObject* words) const |
| 38 | { |
nothing calls this directly
no test coverage detected