Repository navigation
Closed
Labels
bugRelated to a bug, vulnerability, unexpected error with an existing featureRelated to a bug, vulnerability, unexpected error with an existing feature
Description
System Info
langchain verion: 0.0.237
python version: 3.11.4
Who can help?
When loading an OWL graph in the following code, an exception occurs that says: "Exception has occurred: KeyError 'op'". It appears that RFGraph class is having trouble with the owl standard specifically.
graph = RdfGraph(
source_file="example.ttl",
serialization="ttl",
standard="owl"
)
I found this issue when using RDFGraph within the GraphSparqlQAChain class
Thank you very much for your help.
Information
- The official example notebooks/scripts
- My own modified scripts
Related Components
- LLMs/Chat Models
- Embedding Models
- Prompts / Prompt Templates / Prompt Selectors
- Output Parsers
- Document Loaders
- Vector Stores / Retrievers
- Memory
- Agents / Agent Executors
- Tools / Toolkits
- Chains
- Callbacks/Tracing
- Async
Reproduction
Steps to reproduce:
- Use the following code
from langchain.chains import GraphSparqlQAChain
from langchain.graphs import RdfGraph
graph = RdfGraph(
source_file="example.ttl",
serialization="ttl",
standard="owl"
)
graph.load_schema()
print(graph.get_schema)```
- Use the following graph
@prefix : <http://example.org/pump-ontology#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://example.org/test-ontology> .
<http://example.org/test-ontology> rdf:type owl:Ontology .
:hasTopping rdf:type owl:ObjectProperty .
:Object rdf:type owl:Class .
:Pizza rdf:type owl:Class ;
rdfs:subClassOf :Object .
:Topping rdf:type owl:Class ;
rdfs:subClassOf :Object ,
[ rdf:type owl:Restriction ;
owl:onProperty :hasTopping ;
owl:someValuesFrom :Topping
] .
Expected behavior
For the graph to load and for graph.get_schema to produce the classes (Pizza and Topping) and object property (hasTopping) in the class.
Reacted by dosubot
Metadata
Metadata
Assignees
Labels
bugRelated to a bug, vulnerability, unexpected error with an existing featureRelated to a bug, vulnerability, unexpected error with an existing feature
Activity
dosubot commentedon Jul 26, 2023
Answer generated by a 🤖
Answer
I understand that you're encountering an issue with the
RdfGraphclass in the LangChain framework when trying to load an OWL graph. The error message you're seeing, "Exception has occurred: KeyError 'op'", suggests that there's a problem with how theload_schemamethod is handling the OWL standard.From your description, it seems that the issue lies in the
load_schemamethod of theRdfGraphclass. When the standard is set to "owl", the same query (cls_query_owl) is being used to fetch classes, object properties, and data properties. This could be the root cause of the KeyError 'op' exception, as thecls_query_owlquery does not return a column named 'op'.Here's the part of the code that appears to be causing the problem:
To address this issue, you could modify the code as follows:
This modification should resolve the issue by using the correct queries (
op_query_owlanddp_query_owl) to fetch object properties and data properties, respectively.Please note that this is a potential solution based on the information provided. If this solution works for you and you believe it's a bug that could impact other users, I encourage you to make a pull request with this change. If this solution doesn't align with your experience or if the issue persists after trying this solution, I recommend checking if you're using the latest version of LangChain, as the issue might have been addressed in a more recent update.
Sources
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
Fix "missing key op" RDFGraph OWL serialization (#8276)
Caitlin2694 commentedon Jul 27, 2023
Fixed and merged. Thanks all!
Fix "missing key op" RDFGraph OWL serialization (#8276)
Fix "missing key op" RDFGraph OWL serialization (langchain-ai#8276)