linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
561 stars 142 forks source link

removeMetadata #633

Closed bourgeoa closed 3 months ago

bourgeoa commented 5 months ago

store.remove() fails on triple containing a Collection

bourgeoa commented 4 months ago

@jeff-zucker your test return not defined because foo is not declared.

const foo = undefined
if (foo == null)

Here foo is declared and has an undefined value with the equality operator the result will be true when foo is null, undefined or 0 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality

This is used in multiple location in Rdflib

Recently Tim has discovered an issue https://github.com/linkeddata/rdflib.js/issues/639 that seems due to using deep equality and not equality

Le mer. 6 mars 2024, 18:46, Jeff Zucker @.***> a écrit :

@.**** commented on this pull request.

In src/store.ts https://github.com/linkeddata/rdflib.js/pull/633#discussion_r1514915633:

 for (var r = 0; r < requests.length; r++) {

const request = requests[r]

  • if (request !== undefined) {
  • this.removeMatches(request, null, null, meta)
  • if (request != null) { // null or undefined

** I am not sure I understand this - if I create a file containing only if(foo != null) console.log(1); I get ReferenceError: foo is not defined**. So I don't see how this can work. I so much miss perl in this regard where you could just say if(foo) and that would cover null, undefined, and empty.

— Reply to this email directly, view it on GitHub https://github.com/linkeddata/rdflib.js/pull/633#discussion_r1514915633, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ5TZTTKIWTQOXFBP27L2LYW5I6RAVCNFSM6AAAAABCY6JUSWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTSMRQGQZDINJXGU . You are receiving this because you authored the thread.Message ID: @.***>

jeff-zucker commented 4 months ago

AH! Thank you. It works if the variable is declared but not defined but does not work if the variable is not declared, makes sense.

On Sat, Mar 9, 2024 at 8:40 AM Alain Bourgeois @.***> wrote:

@jeff-zucker your test return not defined because foo is not declared.

const foo = undefined
if (foo == null)

Here foo is declared and has an undefined value with the equality operator the result will be true when foo is null, undefined or 0

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality

This is used in multiple location in Rdflib

Recently Tim has discovered an issue https://github.com/linkeddata/rdflib.js/issues/639 that seems due to using deep equality and not equality

Le mer. 6 mars 2024, 18:46, Jeff Zucker @.***> a écrit :

@.**** commented on this pull request.

In src/store.ts https://github.com/linkeddata/rdflib.js/pull/633#discussion_r1514915633:

for (var r = 0; r < requests.length; r++) { const request = requests[r]

  • if (request !== undefined) {
  • this.removeMatches(request, null, null, meta)
  • if (request != null) { // null or undefined

** I am not sure I understand this - if I create a file containing only if(foo != null) console.log(1); I get ReferenceError: foo is not defined**. So I don't see how this can work. I so much miss perl in this regard where you could just say if(foo) and that would cover null, undefined, and empty.

— Reply to this email directly, view it on GitHub https://github.com/linkeddata/rdflib.js/pull/633#discussion_r1514915633,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/AAQ5TZTTKIWTQOXFBP27L2LYW5I6RAVCNFSM6AAAAABCY6JUSWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTSMRQGQZDINJXGU>

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/linkeddata/rdflib.js/pull/633#issuecomment-1986910982, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKVJCJELWNPTZWVI4JLJFY3YXM3QZAVCNFSM6AAAAABCY6JUSWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBWHEYTAOJYGI . You are receiving this because you were mentioned.Message ID: @.***>

jeff-zucker commented 3 months ago

I ran the attached script on solidcommunity.net and it errored with statement to be removed is not in store. I got this error even though there was no collection so I don't think the collection is the problem.

The same script on the test server did not produce an error. But it also did not remove all metadata about the document. Even after the new removeDocument(), there were three statements left over. The predicates related to the document that were not removed were acl, describedBy, and type - things from the link relations.

I am not sure if it was intentional to leave these, but if not, it should be easy to fix.


<script src="https://solidcommunity.net:8443/mashlib.js"></script>                                  
<script type="module">                                                                              

let doc = UI.rdf.sym("https://localhost:8443/public/s/test/tmpr/test.ttl");                         

async function test(){                                                                              
  await UI.store.fetcher.load(doc);                                                                 
  show('load');                                                                               
  await UI.store.removeDocument(doc);                                                                     
  show('removeDocument');;                                                               
}                                                                                                   
test();                                                                                             

function show(msg){                                                                                 
  let stmts  = UI.store.match(null,null,null,doc);                                                  
  console.log(`${stmts.length} statements with graph specified after ` + msg);                      
  stmts  = UI.store.match();                                                                        
  console.log(`${stmts.length} statements with graph not specified after ` + msg);                  
}                                                                                                   

</script>                                                                                           

The document in question looks like this:

<#A> <#isa> <#B>.                                                                                   
<#C> <#isa> <#D>.                                                                                   

The script output was this (notice the 3 in the last one) :

2 statements with graph specified after load
30 statements with graph not specified after load
0 statements with graph specified after removeDocument
3 statements with graph not specified after removeDocument
jeff-zucker commented 3 months ago

Also note that removeDocument did remove everything that had the document as the graph, but the three which were not removed had the document as subject and a blank node as the graph.

bourgeoa commented 3 months ago

Thanks @jeff-zucker for looking at this in detail.

I ran the attached script on solidcommunity.net and it errored with statement to be removed is not in store. I got this error even though there was no collection so I don't think the collection is the problem.

The collection is in the metadata graph. (const meta = this.fetcher?.appNode // this.sym('chrome://TheCurrentSession')) That is were the collection is an issue, not on the document graph The issue is with the last object Collection (full metadata content here https://github.com/linkeddata/rdflib.js/issues/631#issuecomment-1936965762)

  [
     .......
     tabont:status
              ( "[0:16:35.259] N3 parsed: 13 triples in 26 lines."
              "[0:16:35.259] Done." )
  ].

Also note that removeDocument did remove everything that had the document as the graph, but the three which were not removed had the document as subject and a blank node as the graph.

Then these 3 statements are not related to either the graph document or the document part of the metadata graph I shall look where these are created and if they may be removed.

They make no harm for the time being. So I prefer to keep these as an other issue.