From 6b60e13a892dbe8b21daab1584fac5b7e664d8e5 Mon Sep 17 00:00:00 2001 From: Anuneet Anand Date: Sat, 30 Apr 2022 20:55:58 +0530 Subject: [PATCH] Resolves #111 Added support to directly assign and use rdflib graph instead of reading from file, uri or data string. --- ontospy/core/ontospy.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ontospy/core/ontospy.py b/ontospy/core/ontospy.py index 9985c8c..5ad8cfc 100755 --- a/ontospy/core/ontospy.py +++ b/ontospy/core/ontospy.py @@ -48,6 +48,7 @@ def __init__(self, uri_or_path=None, data=None, file_obj=None, + graph_obj=None, rdf_format="", verbose=False, hide_base_schemas=True, @@ -70,6 +71,8 @@ def __init__(self, [description], by default None file_obj : [type], optional [description], by default None + graph_obj : [type], optional + [description], by default None rdf_format : str, optional [description], by default "" verbose : bool, optional @@ -127,8 +130,8 @@ def __init__(self, self.pref_lang) # finally: - if uri_or_path or data or file_obj: - self.load_rdf(uri_or_path, data, file_obj, rdf_format, verbose) + if uri_or_path or data or file_obj or graph_obj: + self.load_rdf(uri_or_path, data, file_obj, graph_obj ,rdf_format, verbose) if build_all: self.build_all( verbose=verbose, @@ -160,13 +163,18 @@ def load_rdf(self, uri_or_path=None, data=None, file_obj=None, + graph_obj=None, rdf_format="", verbose=False): """Load an RDF source into an ontospy/rdflib graph""" - loader = RDFLoader(verbose=verbose) - loader.load(uri_or_path, data, file_obj, rdf_format) - self.rdflib_graph = loader.rdflib_graph - self.sources = loader.sources_valid + if graph_obj: + self.rdflib_graph = graph_obj + self.sources = graph_obj.identifier + else: + loader = RDFLoader(verbose=verbose) + loader.load(uri_or_path, data, file_obj, rdf_format) + self.rdflib_graph = loader.rdflib_graph + self.sources = loader.sources_valid self.sparqlHelper = SparqlHelper(self.rdflib_graph) self.namespaces = sorted(self.rdflib_graph.namespaces())