Skip to content

Commit

Permalink
Resolves lambdamusic#111
Browse files Browse the repository at this point in the history
Added support to directly assign and use rdflib graph instead of reading from file, uri or data string.
  • Loading branch information
anuneetanand committed Apr 30, 2022
1 parent 5f91ab4 commit 6b60e13
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions ontospy/core/ontospy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit 6b60e13

Please sign in to comment.