ali1k / ld-r

Linked Data Reactor (LD-R)
http://ld-r.org
Other
127 stars 30 forks source link

dealing with reading/writing to named graphs and the default graph in GraphDB #73

Open mathib opened 4 years ago

mathib commented 4 years ago

Expected Behavior

By correctly setting the server.js config, I hope to query and write only to the default graph of my GraphDB instance.

Actual Behavior

In the server.js config, I first set the graphName to 'default', but this will also make LD-R retrieve triples from named graphs. When writing triples, they end up in the default graph. This is probably the expected behavior of GraphDB (also see this issue). To query the default graph only, I can write queries using the special named graph http://www.openrdf.org/schema/sesame#nil to limit the query to the default graph.

PREFIX sesame: <http://www.openrdf.org/schema/sesame#>
SELECT *
FROM sesame:nil
WHERE { ?s ?p ?o }

However, when I change in the server.js config the value of graphName to 'http://www.openrdf.org/schema/sesame#nil', I don't see any results appearing in LD-R. When making a new resource in LD-R, it is added to the named graph http://www.openrdf.org/schema/sesame#nil. If I try the same query again directly on GraphDB, I don't see the new resource. Only when I specifically query the named graph itself, I can find it:

PREFIX sesame: <http://www.openrdf.org/schema/sesame#>
SELECT *
WHERE { GRAPH sesame:nil { ?s ?p ?o } }

I don't know which queries are send by LD-R, but I guess the read and write queries use GRAPH, similar as in the last query. Is it possible to make an exception for GraphDB if graphName equals 'http://www.openrdf.org/schema/sesame#nil'? The read queries should be similar as the first query and the write queries should become something like:

INSERT DATA { inst:subj inst:pred inst:obj }

(no named graph in write queries, because it should go in the default graph instead of the 'virtual' named graph http://www.openrdf.org/schema/sesame#nil)

Steps to Reproduce the Problem

Use configs in 'static' mode and run GraphDB locally

Specifications

ali1k commented 4 years ago

Can you check https://github.com/ali1k/ld-r/blob/master/services/utils/helpers.js#L170 to see how read/write behavior for GraphDB is defined?

mathib commented 4 years ago

graphName: 'default'

Read query:

SELECT DISTINCT ?s  ?title   WHERE {
    {
        SELECT DISTINCT ?s WHERE {
            ?s rdf:type ?type . FILTER (?type IN (<https://w3id.org/bot#Site>,<https://w3id.org/bot#Building>,<https://w3id.org/bot#Storey>,<https://w3id.org/bot#Space>,<https://w3id.org/bot#Element>))
        }
        LIMIT 30 OFFSET 0
    }
    OPTIONAL { ?s rdfs:label ?title . }
}

update query:

INSERT DATA {
     <https://mytest.org/nodeA> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/1587740182> .
}

graphName: 'http://www.openrdf.org/schema/sesame#nil'

read query:

SELECT (count(DISTINCT ?s) AS ?total) WHERE {
    GRAPH <http://www.openrdf.org/schema/sesame#nil> {
         ?s rdf:type ?type . FILTER (?type IN (<https://w3id.org/bot#Site>,<https://w3id.org/bot#Building>,<https://w3id.org/bot#Storey>,<https://w3id.org/bot#Space>,<https://w3id.org/bot#Element>))
     }
}

update query:

INSERT DATA {
    GRAPH <http://www.openrdf.org/schema/sesame#nil> {
        <http://ld-r.org/n1587731670> <http://www.w3.org/2000/01/rdf-schema#label> """exampleValue1587740397""" .
    }
}
mathib commented 4 years ago

hmm, I'm exploring GraphDBs way of dealing with NGs and it's pretty confusing at times. A short summary of the behaviour:

My current idea is to add another property for the server.js config besides graphName but for writing: writeGraphName. While graphName would be obligatory, it normally sets the read and write graph during querying using GRAPH <namedgraph> except when default is entered (this is the current situation). If however writeGraphName exists, LD-R should write to the named graph mentioned here using GRAPH <namedgraph> or the default graph in case of default. LD-R still continues to read from the named or default graph as set in graphName.

In case sesame:nil is detected for graphName, the read query should change GRAPH sesame:nil into FROM sesame:nil. The write query should then go to the default graph or if writeGraphName is set, to the named graph set here.