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

Add a method to remove resources from graph #44

Closed

Conversation

claudiu-cristea
Copy link

Fixes #43

@k00ni
Copy link
Member

k00ni commented Jan 15, 2024

@claudiu-cristea thank you, its a helpful addition. Would you mind adding a unit test that covers the new code?

@k00ni k00ni added enhancement New feature or request tests missing labels Jan 15, 2024
@claudiu-cristea
Copy link
Author

I will add but very busy ATM

@k00ni
Copy link
Member

k00ni commented Jan 19, 2024

I didn't check it thoroughly, but do you cover the following cases?

  1. Resource A is subject
  2. Resource A is predicate
  3. Resource A is object

If I understand #43 correctly, all existing instances of a given resource are to be removed. Correct?

@claudiu-cristea
Copy link
Author

If you have these triples:

<http://example.com/subject/1> <http://example.com/predicate/1> "value 1.1.1"
<http://example.com/subject/1> <http://example.com/predicate/1> "value 1.1.2"
<http://example.com/subject/1> <http://example.com/predicate/2> "value 1.2.1"
<http://example.com/subject/1> <http://example.com/predicate/3> "value 1.3.1"
<http://example.com/subject/2> <http://example.com/predicate/1> "value 2.1.1"
<http://example.com/subject/2> <http://example.com/predicate/2> "value 2.2.1"

and I run `$graph->deleteEntireResource('http://example.com/subject/1');

the graph will contain only:

<http://example.com/subject/2> <http://example.com/predicate/1> "value 2.1.1"
<http://example.com/subject/2> <http://example.com/predicate/2> "value 2.2.1"

I'm not sure I understand your case

@k00ni
Copy link
Member

k00ni commented Jan 22, 2024

I'm not sure I understand your case

Lets suppose you have:

<http://foo/1> <http://bar/1> <http://baz/1> .
<http://example/2> <http://foo/1> <http://example/3> .
<http://example/a> <http://example/b> <http://foo/1> .

After calling deleteEntireResource('http://foo/1'); all these triples are gone, because http://foo/1 is part of them. Is that how you want deleteEntireResource to work?

otherwise it would only removes triples which had given
resource as subject, but not predicate or object.
@k00ni
Copy link
Member

k00ni commented Feb 13, 2024

@claudiu-cristea I refined your function based on my last comment. Does it act the way you described it?

@claudiu-cristea
Copy link
Author

claudiu-cristea commented Feb 13, 2024

Initially I didn't think about the triples referring the deleted resources. I really don't know whether we need to delete also those triples. I'm thinking that they can be referred from other graphs (???). No strong opinion. However, if we follow those related resources, I think we need to make this optional (i.e., with an option). Let's not rush, I need to reflect more on this

@zozlak
Copy link

zozlak commented Feb 28, 2024

I guess what you want is to only delete all triples having a given subject.

In such a case I would suggest to make it the easyrdf\Resource::deleteAll() method or adjust the already existing easyrdf\Resource::delete() in a way it can be called with no parameters (which would be interpreted as "delete all").

The tricky part about it is the state of the easyrdf\Resource object after the removal of all triples having it as a subject. If a given easyrdf\Resource was only used as a subject, it will be left in an "existing but not-used" state. From the pragmatic perspective I don't think it's an issue though. The user doesn't care as (s)he got what (s)he wanted and we already can create easyrdf\Resource in such a state:

$graph = new easyrdf\Graph();
$resource = $graph->resource('https://foo');

so it would not any new corner case to the library.

The problem with the easyrdf\Graph::deleteWholeResource() is as outlined by @k00ni - in the easyrdf data model a resource represents both triples' subjects, predicates (properties) and objects so the easyrdf\Graph::deleteWholeResource() sounds quite ambiguous.

@claudiu-cristea
Copy link
Author

@zozlak

I guess what you want is to only delete all triples having a given subject.

Yes, this is exactly what I need.

In such a case I would suggest to make it the easyrdf\Resource::deleteAll() method...

Sounds better. I will provide shortly some commits on this direction

@k00ni
Copy link
Member

k00ni commented May 9, 2024

Closed for now to avoid stale PRs. Also, @zozlak made some good points.

Please get back to me if you wanna continue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to delete an entire resource from a graph?
3 participants