Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trying rdflib-sqlalchemy fork (#110)
* moving around * adding in rdflib as subpackage of brickschema * remove symlink * no modules * fixing deps * fixing import * fix import * fix import * trying new version * try new package version * rdflibsqlalchemy fork shoul work now * bump deps * Refactored graph name handling to use URIRef. * aider: Override the `triples` method in `PersistentGraph` to query across 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. * try new version of dependency * bump rdflib dep, version
- Loading branch information