Skip to content

langchain.graph RDFGraph does not read OWL  #8263

Closed

Description

@Caitlin2694

System Info

langchain verion: 0.0.237
python version: 3.11.4

Who can help?

Harrison Chase (@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.

Activity

  1. added
    bugRelated to a bug, vulnerability, unexpected error with an existing feature
    on Jul 26, 2023
  2. dosubot commented on Jul 26, 2023

    @dosubot

    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.

  3. Caitlin2694 commented on Jul 27, 2023

    @Caitlin2694
    ContributorAuthor

    Fixed and merged. Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions