mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
community[patch]: Pass kwargs to SPARQLStore from RdfGraph (#20385)
This introduces `store_kwargs` which behaves similarly to `graph_kwargs` on the `RdfGraph` object, which will enable users to pass `headers` and other arguments to the underlying `SPARQLStore` object. I have also made a [PR in `rdflib` to support passing `default_graph`](https://github.com/RDFLib/rdflib/pull/2761). Example usage: ```python from langchain_community.graphs import RdfGraph graph = RdfGraph( query_endpoint="http://localhost/sparql", standard="rdf", store_kwargs=dict( default_graph="http://example.com/mygraph" ) ) ``` <!--If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, hwchase17.--> --------- Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
e57cf73cf5
commit
f931a9ce60
@ -117,6 +117,7 @@ class RdfGraph:
|
|||||||
standard: Optional[str] = "rdf",
|
standard: Optional[str] = "rdf",
|
||||||
local_copy: Optional[str] = None,
|
local_copy: Optional[str] = None,
|
||||||
graph_kwargs: Optional[Dict] = None,
|
graph_kwargs: Optional[Dict] = None,
|
||||||
|
store_kwargs: Optional[Dict] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Set up the RDFlib graph
|
Set up the RDFlib graph
|
||||||
@ -130,6 +131,9 @@ class RdfGraph:
|
|||||||
:param graph_kwargs: Additional rdflib.Graph specific kwargs
|
:param graph_kwargs: Additional rdflib.Graph specific kwargs
|
||||||
that will be used to initialize it,
|
that will be used to initialize it,
|
||||||
if query_endpoint is provided.
|
if query_endpoint is provided.
|
||||||
|
:param store_kwargs: Additional sparqlstore.SPARQLStore specific kwargs
|
||||||
|
that will be used to initialize it,
|
||||||
|
if query_endpoint is provided.
|
||||||
"""
|
"""
|
||||||
self.source_file = source_file
|
self.source_file = source_file
|
||||||
self.serialization = serialization
|
self.serialization = serialization
|
||||||
@ -174,12 +178,13 @@ class RdfGraph:
|
|||||||
self.graph.parse(source_file, format=self.serialization)
|
self.graph.parse(source_file, format=self.serialization)
|
||||||
|
|
||||||
if query_endpoint:
|
if query_endpoint:
|
||||||
|
store_kwargs = store_kwargs or {}
|
||||||
self.mode = "store"
|
self.mode = "store"
|
||||||
if not update_endpoint:
|
if not update_endpoint:
|
||||||
self._store = sparqlstore.SPARQLStore()
|
self._store = sparqlstore.SPARQLStore(**store_kwargs)
|
||||||
self._store.open(query_endpoint)
|
self._store.open(query_endpoint)
|
||||||
else:
|
else:
|
||||||
self._store = sparqlstore.SPARQLUpdateStore()
|
self._store = sparqlstore.SPARQLUpdateStore(**store_kwargs)
|
||||||
self._store.open((query_endpoint, update_endpoint))
|
self._store.open((query_endpoint, update_endpoint))
|
||||||
graph_kwargs = graph_kwargs or {}
|
graph_kwargs = graph_kwargs or {}
|
||||||
self.graph = rdflib.Graph(self._store, **graph_kwargs)
|
self.graph = rdflib.Graph(self._store, **graph_kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user