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

Trying rdflib-sqlalchemy fork #110

Merged
merged 16 commits into from
Feb 21, 2024
Merged

Trying rdflib-sqlalchemy fork #110

merged 16 commits into from
Feb 21, 2024

Conversation

gtfierro
Copy link
Member

No description provided.

…ross all contexts if no specific context is provided.

# Aider chat conversation:

USER: add `brickschema/persistent.py`

ASSISTANT: It looks like you've added `brickschema/persistent.py` to our workspace for potential modifications. How can I assist you with this file?

USER: Please help me debug my code. I can insert triples into the `PersistentGraph`, but when I try to loop through the triples like `self.triples((None, NOne, None))`, nothing is returned.

ASSISTANT: It seems like the issue might be related to how the triples are being inserted and then queried. Given the description of the problem, it's possible that the triples are being inserted into a specific graph context within the `PersistentGraph`, but when querying with `self.triples((None, None, None))`, it's attempting to query the default graph context which might not contain any triples.

To address this, we need to ensure that when querying for triples, we're querying across all graph contexts if that's the intended behavior. This can be achieved by modifying the `__len__` and `triples` methods to correctly handle querying across all contexts in the `PersistentGraph` class.

Here's a proposed change to ensure that the `triples` method queries across all contexts:

```diff
--- brickschema/persistent.py
+++ brickschema/persistent.py
@@ ... @@
 class PersistentGraph(Graph):
+    def triples(self, triple_pattern, context=None):
+        """
+        Override the triples method to query across all contexts if no specific context is provided.
+        """
+        if context is None:
+            # Query across all contexts
+            return super().triples(triple_pattern, context=self)
+        else:
+            # Query within the specified context
+            return super().triples(triple_pattern, context=context)
```

This change adds an override for the `triples` method in the `PersistentGraph` class. When no specific context is provided, it queries across all contexts by passing `self` as the context to the parent method. This ensures that when you call `self.triples((None, None, None))`, it will return triples from all contexts within the `PersistentGraph`.

Please note, this is a general approach and might need adjustments based on the specific structure and requirements of your application. If your application relies on querying specific contexts, ensure that the context is correctly specified when calling the `triples` method.
@gtfierro gtfierro merged commit 713e49c into master Feb 21, 2024
4 checks passed
@gtfierro gtfierro deleted the trying-diff-package branch February 21, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant