Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

langchain.graph RDFGraph does not read OWL #8263

Closed
2 of 14 tasks
Caitlin2694 opened this issue Jul 26, 2023 · 2 comments
Closed
2 of 14 tasks

langchain.graph RDFGraph does not read OWL #8263

Caitlin2694 opened this issue Jul 26, 2023 · 2 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: doc loader Related to document loader module (not documentation)

Comments

@Caitlin2694
Copy link
Contributor

System Info

langchain verion: 0.0.237
python version: 3.11.4

Who can help?

@hwchase17

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:

  1. 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)```
  1. 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.

@dosubot dosubot bot added Ɑ: doc loader Related to document loader module (not documentation) 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Jul 26, 2023
@dosubot
Copy link

dosubot bot commented Jul 26, 2023

Answer generated by a 🤖

Answer

I understand that you're encountering an issue with the RdfGraph class 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 the load_schema method is handling the OWL standard.

From your description, it seems that the issue lies in the load_schema method of the RdfGraph class. 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 the cls_query_owl query does not return a column named 'op'.

Here's the part of the code that appears to be causing the problem:

elif self.standard == "owl":
    clss = self.query(cls_query_owl)
    ops = self.query(cls_query_owl)  # This should be op_query_owl
    dps = self.query(cls_query_owl)  # This should be dp_query_owl
    ...

To address this issue, you could modify the code as follows:

elif self.standard == "owl":
    clss = self.query(cls_query_owl)
    ops = self.query(op_query_owl)  # Corrected
    dps = self.query(dp_query_owl)  # Corrected
    ...

This modification should resolve the issue by using the correct queries (op_query_owl and dp_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.

baskaryan pushed a commit that referenced this issue Jul 26, 2023
Replace this comment with:
- Description: Fix "missing key op" error in RDFGraph OWL Serialization
  - Issue: #8263
  - Dependencies: None
  - Tag maintainer: @baskaryan
@Caitlin2694
Copy link
Contributor Author

Fixed and merged. Thanks all!

hinthornw pushed a commit that referenced this issue Jul 27, 2023
Replace this comment with:
- Description: Fix "missing key op" error in RDFGraph OWL Serialization
  - Issue: #8263
  - Dependencies: None
  - Tag maintainer: @baskaryan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: doc loader Related to document loader module (not documentation)
Projects
None yet
Development

No branches or pull requests

1 participant