DerwenAI / kglab

Graph Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, NetworkX, RAPIDS, RDFlib, pySHACL, PyVis, morph-kgc, pslpython, pyarrow, etc.
https://derwen.ai/docs/kgl/
MIT License
574 stars 65 forks source link

return all namespaces #199

Closed ceteri closed 2 years ago

ceteri commented 3 years ago

Note that get_ns_dict() only returns the prefix:uri pairs that have been added explicitly to a kglab.KnowledgeGraph object instances.

It should be returning the union of the namespaces referenced by each of the parses, loads, and explicit namespace additions.

Here's example code to fix the method's returned value:

kg = kglab.KnowledgeGraph()
kg.load_rdf("dat/wtm.ttl", format="ttl")

nm = kg.rdf_graph().namespace_manager
ns = {
    prefix: uri
    for prefix, uri in nm.namespaces()
}

return ns