| 35 | } |
| 36 | |
| 37 | double CoherenceObject::getScore(PyObject* words) const |
| 38 | { |
| 39 | vector<tomoto::Vid> wordIds; |
| 40 | py::foreach<string>(words, [&](const string& w) |
| 41 | { |
| 42 | auto wid = corpus->getVocabDict().toWid(w); |
| 43 | if (wid != tomoto::non_vocab_id) wordIds.emplace_back(wid); |
| 44 | }, "`words` must be an iterable of `str`."); |
| 45 | |
| 46 | switch (seg) |
| 47 | { |
| 48 | case Segmentation::one_one: |
| 49 | return model.template getScore<Segmentation::one_one>(cm, wordIds.begin(), wordIds.end()); |
| 50 | case Segmentation::one_pre: |
| 51 | return model.template getScore<Segmentation::one_pre>(cm, wordIds.begin(), wordIds.end()); |
| 52 | case Segmentation::one_suc: |
| 53 | return model.template getScore<Segmentation::one_suc>(cm, wordIds.begin(), wordIds.end()); |
| 54 | case Segmentation::one_all: |
| 55 | return model.template getScore<Segmentation::one_all>(cm, wordIds.begin(), wordIds.end()); |
| 56 | case Segmentation::one_set: |
| 57 | return model.template getScore<Segmentation::one_set>(cm, wordIds.begin(), wordIds.end()); |
| 58 | default: |
| 59 | throw py::ValueError{ "invalid Segmentation `seg`" }; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void addCoherenceTypes(py::Module& module) |
| 64 | { |
nothing calls this directly
no test coverage detected