Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_rdf(self,
uri_or_path=None,
data=None,
file_obj=None,
rdf_format="",
verbose=False,
hide_base_schemas=True,
hide_implicit_types=True,
hide_implicit_preds=True):
"""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
self.sparqlHelper = SparqlHelper(self.rdflib_graph)
self.namespaces = sorted(self.rdflib_graph.namespaces())
def __init__(self, rdfgraph, sparql_endpoint=False):
super(SparqlHelper, self).__init__()
self.rdflib_graph = rdfgraph
self.sparql_endpoint = sparql_endpoint
# Bind a few prefix, namespace pairs for easier sparql querying
self.rdflib_graph.bind("rdf", rdflib.namespace.RDF)
self.rdflib_graph.bind("rdfs", rdflib.namespace.RDFS)
self.rdflib_graph.bind("owl", rdflib.namespace.OWL)
self.rdflib_graph.bind("skos", rdflib.namespace.SKOS)
self.rdflib_graph.bind("dc", "http://purl.org/dc/elements/1.1/")
self.rdflib_graph.bind("vann", "http://purl.org/vocab/vann/")
self.rdflib_graph.bind("void", "http://rdfs.org/ns/void#")
self.rdflib_graph.bind("xsd", "http://www.w3.org/2001/XMLSchema#")
self.rdflib_graph.bind("sh", "http://www.w3.org/ns/shacl#")
"""
try:
# graph = rdflib.Graph('SPARQLStore')
# graph = rdflib.ConjunctiveGraph('SPARQLStore')
graph = rdflib.ConjunctiveGraph('SPARQLUpdateStore')
if credentials and type(credentials) == tuple:
# https://github.com/RDFLib/rdflib/issues/343
graph.store.setCredentials(credentials[0], credentials[1])
# graph.store.setHTTPAuth('BASIC') # graph.store.setHTTPAuth('DIGEST')
graph.open(sparql_endpoint)
self.rdflib_graph = graph
self.sparql_endpoint = sparql_endpoint
self.sources = [sparql_endpoint]
self.sparqlHelper = SparqlHelper(self.rdflib_graph, self.sparql_endpoint)
self.namespaces = sorted(self.rdflib_graph.namespaces())
except:
printDebug("Error trying to connect to Endpoint.")
raise
# don't extract entities by default..