MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / pyKnowledgeGraph

Method pyKnowledgeGraph

include/bind.h:246–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244
245 template<class... Args>
246 pyKnowledgeGraph(py::handle scope, const char *name, const Args &...args) :
247 Base(scope, signature(name, typeid(Index).name()).c_str(), args...) {
248 attr("__doc__") = "KnowledgeGraph(index_type=dtype.uint32)"
249 R"(
250 Knowledge graphs.
251
252 Parameters:
253 index_type (dtype): type of node indexes
254 )";
255
256 // override instance name with template name
257 attr("__name__") = py::internal_str(name);
258 attr("__qualname__") = py::internal_str(name);
259
260 // data members
261 def_readonly("num_vertex", &KnowledgeGraph::num_vertex);
262 def_readonly("num_edge", &KnowledgeGraph::num_edge);
263 def_readonly("num_relation", &KnowledgeGraph::num_relation);
264 def_readonly("normalization", &KnowledgeGraph::normalization);
265 def_readonly("entity2id", &KnowledgeGraph::entity2id, "Map of entity name to index.");
266 def_readonly("relation2id", &KnowledgeGraph::relation2id, "Map of relation name to index.");
267 def_readonly("id2entity", &KnowledgeGraph::id2entity, "Map of entity index to name.");
268 def_readonly("id2relation", &KnowledgeGraph::id2relation, "Map of relation index to name.");
269
270 // member functions
271 def(py::init<>(), py::no_gil());
272
273 def("load", &KnowledgeGraph::load_file, py::no_gil(),
274 py::arg("file_name"), py::arg("normalization") = false, py::arg("delimiters") = " \t\r\n",
275 py::arg("comment") = "#",
276 "load(*args, **kwargs)"
277 R"(
278 Load a knowledge graph from a triplet-list file. Store the graph in an adjacency list.
279
280 This function has 3 overloads
281
282 .. function:: load(file_name, normalization=False, delimiters=' \\t\\r\\n', comment='#')
283 .. function:: load(triplet_list, normalization=False)
284 .. function:: load(weighted_triplet_list, normalization=False)
285
286 Parameters:
287 file_name (str): file name
288 triplet_list (list of (str, str, str)): triplet list
289 weighted_triplet_list (list of (str, str, str, float)): weighted triplet list
290 normalization (bool, optional): normalize the adjacency matrix or not
291 delimiters (str, optional): string of delimiter characters
292 comment (str, optional): prefix of comment strings
293 )");
294
295 def("load", &KnowledgeGraph::load_triplet_list, py::no_gil(),
296 py::arg("triplet_list"), py::arg("normalization") = false);
297
298 def("load", &KnowledgeGraph::load_weighted_triplet_list, py::no_gil(),
299 py::arg("weighted_triplet_list"), py::arg("normalization") = false);
300
301 def("save", &KnowledgeGraph::save, py::no_gil(),
302 py::arg("file_name"), py::arg("anonymous") = false,
303 "save(file_name, anonymous=False)"

Callers

nothing calls this directly

Calls 2

signatureFunction · 0.70
nameMethod · 0.45

Tested by

no test coverage detected