| 1256 | } |
| 1257 | |
| 1258 | py::UniqueCObj<PhraserObject> PhraserObject::load(PyObject* cls, const std::string& path) |
| 1259 | { |
| 1260 | if (!cls) cls = (PyObject*)py::Type<PhraserObject>; |
| 1261 | else if (!PyObject_IsSubclass(cls, (PyObject*)py::Type<PhraserObject>)) throw runtime_error{ "`cls` must be a derived class of `Phraser`." }; |
| 1262 | |
| 1263 | ifstream ifs{ path }; |
| 1264 | if (!ifs) throw py::OSError{ string{"cannot read from '"} + path + "'" }; |
| 1265 | py::UniqueCObj<PhraserObject> ret{ (PhraserObject*)PyObject_CallObject(cls, nullptr) }; |
| 1266 | if (!ret) throw py::ExcPropagation{}; |
| 1267 | tomoto::serializer::readMany(ifs, tomoto::serializer::to_keyz("tph1"), |
| 1268 | ret->vocabs, |
| 1269 | ret->cand_info, |
| 1270 | ret->trie_nodes |
| 1271 | ); |
| 1272 | return ret; |
| 1273 | } |
| 1274 | |
| 1275 | void addUtilsTypes(py::Module& module) |
| 1276 | { |