langchain_community.graphs.ontotext_graphdb_graph.OntotextGraphDBGraph

class langchain_community.graphs.ontotext_graphdb_graph.OntotextGraphDBGraph(query_endpoint: str, query_ontology: Optional[str] = None, local_file: Optional[str] = None, local_file_format: Optional[str] = None)[source]

Ontotext GraphDB https://graphdb.ontotext.com/ wrapper for graph operations.

Security note: Make sure that the database connection uses credentials

that are narrowly-scoped to only include necessary permissions. Failure to do so may result in data corruption or loss, since the calling code may attempt commands that would result in deletion, mutation of data if appropriately prompted or reading sensitive data if such data is present in the database. The best way to guard against such negative outcomes is to (as appropriate) limit the permissions granted to the credentials used with this tool.

See https://python.langchain.com/docs/security for more information.

Set up the GraphDB wrapper

Parameters
  • query_endpoint (str) – SPARQL endpoint for queries, read access

  • query_ontology (Optional[str]) –

  • local_file (Optional[str]) –

  • local_file_format (Optional[str]) –

If GraphDB is secured, set the environment variables ‘GRAPHDB_USERNAME’ and ‘GRAPHDB_PASSWORD’.

Parameters
  • query_ontology (Optional[str]) – a CONSTRUCT query that is executed

  • query_endpoint (str) –

  • local_file (Optional[str]) –

  • local_file_format (Optional[str]) –

on the SPARQL endpoint and returns the KG schema statements Example: ‘CONSTRUCT {?s ?p ?o} FROM <https://example.com/ontology/> WHERE {?s ?p ?o}’ Currently, DESCRIBE queries like ‘PREFIX onto: <https://example.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> DESCRIBE ?term WHERE {

?term rdfs:isDefinedBy onto:

}’ are not supported, because DESCRIBE returns the Symmetric Concise Bounded Description (SCBD), i.e. also the incoming class links. In case of large graphs with a million of instances, this is not efficient. Check https://github.com/eclipse-rdf4j/rdf4j/issues/4857

Parameters
  • local_file (Optional[str]) – a local RDF ontology file.

  • query_endpoint (str) –

  • query_ontology (Optional[str]) –

  • local_file_format (Optional[str]) –

Supported RDF formats: Turtle, RDF/XML, JSON-LD, N-Triples, Notation-3, Trig, Trix, N-Quads. If the rdf format can’t be determined from the file extension, pass explicitly the rdf format in local_file_format param.

Parameters
  • local_file_format (Optional[str]) – Used if the rdf format can’t be determined

  • query_endpoint (str) –

  • query_ontology (Optional[str]) –

  • local_file (Optional[str]) –

from the local file extension. One of “json-ld”, “xml”, “n3”, “turtle”, “nt”, “trig”, “nquads”, “trix”

Either query_ontology or local_file should be passed.

Attributes

get_schema

Returns the schema of the graph database in turtle format

Methods

__init__(query_endpoint[, query_ontology, ...])

Set up the GraphDB wrapper

query(query)

Query the graph.

__init__(query_endpoint: str, query_ontology: Optional[str] = None, local_file: Optional[str] = None, local_file_format: Optional[str] = None) None[source]

Set up the GraphDB wrapper

Parameters
  • query_endpoint (str) – SPARQL endpoint for queries, read access

  • query_ontology (Optional[str]) –

  • local_file (Optional[str]) –

  • local_file_format (Optional[str]) –

Return type

None

If GraphDB is secured, set the environment variables ‘GRAPHDB_USERNAME’ and ‘GRAPHDB_PASSWORD’.

Parameters
  • query_ontology (Optional[str]) – a CONSTRUCT query that is executed

  • query_endpoint (str) –

  • local_file (Optional[str]) –

  • local_file_format (Optional[str]) –

Return type

None

on the SPARQL endpoint and returns the KG schema statements Example: ‘CONSTRUCT {?s ?p ?o} FROM <https://example.com/ontology/> WHERE {?s ?p ?o}’ Currently, DESCRIBE queries like ‘PREFIX onto: <https://example.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> DESCRIBE ?term WHERE {

?term rdfs:isDefinedBy onto:

}’ are not supported, because DESCRIBE returns the Symmetric Concise Bounded Description (SCBD), i.e. also the incoming class links. In case of large graphs with a million of instances, this is not efficient. Check https://github.com/eclipse-rdf4j/rdf4j/issues/4857

Parameters
  • local_file (Optional[str]) – a local RDF ontology file.

  • query_endpoint (str) –

  • query_ontology (Optional[str]) –

  • local_file_format (Optional[str]) –

Return type

None

Supported RDF formats: Turtle, RDF/XML, JSON-LD, N-Triples, Notation-3, Trig, Trix, N-Quads. If the rdf format can’t be determined from the file extension, pass explicitly the rdf format in local_file_format param.

Parameters
  • local_file_format (Optional[str]) – Used if the rdf format can’t be determined

  • query_endpoint (str) –

  • query_ontology (Optional[str]) –

  • local_file (Optional[str]) –

Return type

None

from the local file extension. One of “json-ld”, “xml”, “n3”, “turtle”, “nt”, “trig”, “nquads”, “trix”

Either query_ontology or local_file should be passed.

query(query: str) List[rdflib.query.ResultRow][source]

Query the graph.

Parameters

query (str) –

Return type

List[rdflib.query.ResultRow]

Examples using OntotextGraphDBGraph