blazegraph / database

Blazegraph High Performance Graph Database
GNU General Public License v2.0
891 stars 172 forks source link

Trying to put the content of a ttl file in a named graph #158

Open HackerBaloo opened 4 years ago

HackerBaloo commented 4 years ago

Running Blazegraph 2.1.6RC I'm trying to put the content of: Brick-v1.1.0-rc1.ttl in a named graph in blazegraph. I use libcurl to upload the file, and that works.

But when I add ?using-graph-uri=brick or ?using-named-graph-uri=brick to the URL, it doesn't make any difference. My URL: http://localhost/blazegraph/sparql?using-graph-uri=brick I also tried this: http://localhost/blazegraph/sparql?context-uri=https://brickschema.org With context URI blazegraph complained when I didn't have a full uri as context In the header: Content-Type: application/x-turtle And I make a post with the file in the body. I test i with this query (or with FROM https://brickschema.org for the context-uri case):

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX brick: <https://brickschema.org/schema/1.1/Brick#>
SELECT ?s ?p ?o 
FROM <brick>
WHERE
{?s ?p ?o .
 ?s rdfs:subClassOf brick:Class. }

This gives any empty response. While this, without any named graph, still gives the full response:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX brick: <https://brickschema.org/schema/1.1/Brick#>
SELECT ?s ?p ?o 
WHERE
{?s ?p ?o .
 ?s rdfs:subClassOf brick:Class. }

Should it work? Any other way to accomplish this?

HackerBaloo commented 4 years ago

I then tried using command line curl like in the sample here Like this:

curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:80/bigdata/sparql?context-uri=https://brickschema.org'

But in that case I don't get any brick:Class with either select from above. Is context here something other than a named graph?

HackerBaloo commented 4 years ago

OK, now I'm getting somewhere, I noticed that the upload example used the old bigdata instead of blazegraph in the URL. Changing that made the upload really work. Both with context-uri and with using-graph-uri.

And I can do a select without the "FROM" part, if I add either context-uri or using-graph-uri. But I was under the impression that using the URL-parameter using-graph-uri should be interchangable with a FROM statment in the select statement.

curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:80/blazegraph/sparql?using-graph-uri=https://brickschema.org'
curl -X POST http://localhost/blazegraph/sparql?using-graph-uri=https://brickschema.org --data-urlencode 'query=PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX brick: <https://brickschema.org/schema/1.1/Brick#> SELECT ?s ?p ?o WHERE {?s ?p ?o . ?s rdfs:subClassOf brick:Class. }' -H 'Accept:application/sparql-results+json'

Gives the result. But I still don't get anything from this query in the WebUI:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX brick: <https://brickschema.org/schema/1.1/Brick#>
SELECT ?s ?p ?o 
FROM NAMED <https://brickschema.org>
WHERE
{?s ?p ?o .
 ?s rdfs:subClassOf brick:Class. }
aindlq commented 4 years ago

I believe you confused a bit the meaning of FROM and FROM NAMED.

From the spec https://www.w3.org/TR/sparql11-query/#specifyingDataset:

If there is no FROM clause, but there is one or more FROM NAMED clauses, then the dataset includes an empty graph for the default graph.

In your last query you probably wanted to use FROM instead of FROM NAMED.

FROM and FROM NAMED corresponds to using-graph-uri and using-named-graph-uri respectively:

HackerBaloo commented 4 years ago

bg.zip Well, I hope I have misunderstood something. But I do get results when I add either using-graph-uri or using-named-graph-uri to the url, but I don't get any result when I add either FROM or FROM NAMED to the query. Attached is exactly what I have tested and a way to reproduce it.

mschmidt00 commented 4 years ago

A couple of comments/ideas:

1.) As suggested previously, for your query you should always use FROM: FROM restricts the default graph, which is what's mapped when using "plain" triple patterns, whereas FROM NAMED affects the behavior of those triple patterns nested into "GRAPH { }" clauses.

2.) As per the SPARQL 1.1 protocol, using-graph-uri (and using-named-graph-uri) are dedicated to update queries: https://www.w3.org/TR/sparql11-protocol/#update-operation. As you're dealing with SELECT queries, the right thing to use instead would be default-graph-uri (or named-graph-uri), as documented in section https://www.w3.org/TR/sparql11-protocol/#query-operation of the standard. FROM should be equivalent to using default-graph-uri.

3.) If FROM clauses are not working properly (i.e., give you an empty result for your query), then the most likely root cause is that your data has not been loaded into the right named graph. Could you try running a query such as "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } }" to understand which named graph(s) your data has been added into?

HackerBaloo commented 4 years ago

OK, I tried 8 different uploads that all reports: "data modified="19167" suggesting that they all succeed.

curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:9999/blazegraph/sparql?using-graph-uri=https%3A%2F%2Fbrickschema.org'
curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:9999/blazegraph/sparql?using-graph-uri=https://brickschema.org'
curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:9999/blazegraph/sparql?using-graph-uri=%3Chttps%3A%2F%2Fbrickschema.org%3C'
curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:9999/blazegraph/sparql?using-graph-uri=<https://brickschema.org>'

curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:9999/blazegraph/sparql?using-named-graph-uri=https%3A%2F%2Fbrickschema.org'
curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:9999/blazegraph/sparql?using-named-graph-uri=https://brickschema.org'
curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:9999/blazegraph/sparql?using-named-graph-uri=%3Chttps%3A%2F%2Fbrickschema.org%3C'
curl -D- -H 'Content-Type: text/turtle' --upload-file Brick-v1.1.0-rc1.ttl -X POST 'http://localhost:9999/blazegraph/sparql?using-named-graph-uri=<https://brickschema.org>'

but the query you suggested, a very good suggestion, I was tying to figure out how to do that:

SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } }

just returns this:

{
  "head" : {
    "vars" : [ "g" ]
  },
  "results" : {
    "bindings" : [ {
      "g" : {
        "type" : "uri",
        "value" : "http://www.bigdata.com/rdf#nullGraph"
      }
    } ]
  }
}
dgarijo commented 4 years ago

I am experiencing the same exact problem. Uploading data to a named graph doesn't seem to work (all are loaded into the nullGraph as described by @HackerBaloo). Is there any advice on how to overcome this problem?

dgarijo commented 4 years ago

I found the answer. By using context-uri the data is uploaded to the right named graph:

curl -D- -H 'Content-Type: text/turtle' --upload-file test.ttl -X POST 'http://blazegraph_instance/.../sparql?context-uri=https://named_graph_name'

Then, when doing the query:

select ?a ?b ?c from <https://named_graph_name> where {
  ?a ?b ?c
}limit 100

I get the right results

ns706 commented 4 years ago

If you want to query the named graph without using the default graph, this should work:

select ?a ?b ?c from named <https://named_graph_name> where { graph <https://named_graph_name> {?a ?b ?c} }limit 100

larjohn commented 3 years ago

I found the answer. By using context-uri the data is uploaded to the right named graph:

curl -D- -H 'Content-Type: text/turtle' --upload-file test.ttl -X POST 'http://blazegraph_instance/.../sparql?context-uri=https://named_graph_name'

Then, when doing the query:

select ?a ?b ?c from <https://named_graph_name> where {
  ?a ?b ?c
}limit 100

I get the right results

My graph was named with the uploaded file name instead of context-uri