| 188 | |
| 189 | template<class Index = size_t> |
| 190 | class pyWordGraph : public py::class_<graphvite::WordGraph<Index>, graphvite::Graph<Index>> { |
| 191 | public: |
| 192 | typedef graphvite::WordGraph<Index> WordGraph; |
| 193 | typedef py::class_<WordGraph, graphvite::Graph<Index>> Base; |
| 194 | using Base::attr; |
| 195 | using Base::def; |
| 196 | using Base::def_readonly; |
| 197 | |
| 198 | template<class... Args> |
| 199 | pyWordGraph(py::handle scope, const char *name, const Args &...args) : |
| 200 | Base(scope, signature(name, typeid(Index).name()).c_str(), args...) { |
| 201 | attr("__doc__") = "WordGraph(index_type=dtype.uint32)" |
| 202 | R"( |
| 203 | Normal graphs of word co-occurrences. |
| 204 | |
| 205 | Parameters: |
| 206 | index_type (dtype): type of node indexes |
| 207 | )"; |
| 208 | |
| 209 | // override instance name with template name |
| 210 | attr("__name__") = py::internal_str(name); |
| 211 | attr("__qualname__") = py::internal_str(name); |
| 212 | |
| 213 | // member functions |
| 214 | def(py::init<>(), py::no_gil()); |
| 215 | |
| 216 | def("load", &WordGraph::load_file_compact, py::no_gil(), |
| 217 | py::arg("file_name"), py::arg("window") = 5, py::arg("min_count") = 5, py::arg("normalization") = false, |
| 218 | py::arg("delimiters") = " \t\r\n", py::arg("comment") = "#", |
| 219 | R"(load(file_name, window=5, min_count=5, normalization=False, delimiters=' \\t\\r\\n', comment='#'))" |
| 220 | R"( |
| 221 | Load a word graph from a corpus file. Store the graph in an adjacency list. |
| 222 | |
| 223 | Parameters: |
| 224 | file_name (str): file name |
| 225 | window (int, optional): word pairs with distance <= window are counted as edges |
| 226 | min_count (int, optional): words with occurrence <= min_count are discarded |
| 227 | normalization (bool, optional): normalize the adjacency matrix or not |
| 228 | delimiters (str, optional): string of delimiter characters |
| 229 | comment (str, optional): prefix of comment strings |
| 230 | )"); |
| 231 | |
| 232 | def("__repr__", &WordGraph::info, py::no_gil()); |
| 233 | } |
| 234 | }; |
| 235 | |
| 236 | template<class Index = size_t> |
| 237 | class pyKnowledgeGraph : public py::class_<graphvite::KnowledgeGraph<Index>> { |
nothing calls this directly
no outgoing calls
no test coverage detected