0

I am trying the tutorials of Jena here. I encounter similar problem with this question, but it does not solve my problem. I've already loaded my data into tdb and when I query with SELECT DISTINCT ?g {GRAPH ?g {}}, the results are as follows:

-----------------
| g             |
=================
| <ds-ng-1.ttl> |
| <ds-ng-2.ttl> |
-----------------

but when i try to query with following query in tdb I've got no results.

PREFIX  dc:     <http://purl.org/dc/elements/1.1/>
PREFIX  :       <.>

SELECT ?title
{ 
  GRAPH :ds-ng-2.ttl
      { ?b dc:title ?title }
}

According to the similar question I've mentioned above, @RobV mentioned

If you get an absolute URI back then you can specify that directly in your original query, if you do not then there is no way to query for it from the command line.

I'd like to ask is it real? If so, how can I use API to execute this query? My codes are as follows:

    String directory = "path_to\\datasets\\data_graph\\tdbtest";
    Dataset dataset = TDBFactory.createDataset(directory);  
    Model tdb = dataset.getDefaultModel();
    String queryString = "PREFIX  dc:<http://purl.org/dc/elements/1.1/> \nPREFIX  :  <.> \nSELECT ?title { GRAPH :ds-ng-2.ttl { ?b dc:title ?title }}";
    Query query = QueryFactory.create(queryString);
    try(QueryExecution qexec = QueryExecutionFactory.create(query, tdb)){
        ResultSet results = qexec.execSelect();
        ResultSetFormatter.out(System.out, results, query) ;
    }

But I still get now results. I'm not sure how I can select multiple models no matter it's a default or named model.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Charlotte
  • 93
  • 11
  • You have to use the same `BASE` in the SPARQL query as you had when loading the data into the graph. Or how did you load the data? – UninformedUser Feb 20 '17 at 04:58
  • I use tdbloader to load the data with `tdbloader --loc=path\to\tdb -graph=ds-ng-1.ttl ds-ng-1.ttl` and `tdbloader --loc=path\to\tdb -graph=ds-ng-2.ttl ds-ng-2.ttl` to load the two named graphs, I'm not sure if i am correct about loading named graphs. I try to use the local file location as `base` but sparql gives me a syntax error. I do not know whether I can use a local directory as base. – Charlotte Feb 20 '17 at 05:14
  • What do you write for `BASE` in the query and which syntax error? And why don't you use a full URI as graph when loading? – UninformedUser Feb 20 '17 at 06:29
  • I use `BASE `. The error is `Encountered " "C: "" at line 3, column 6. Was expecting: ...`. When you talking about using a full URI, do you mean to use `tdbloader --loc=path\to\tdb -graph=ds-ng-1.ttl C:\Users\weiling\Documents\datasets\data_graph\ds-ng-1.ttl`?? – Charlotte Feb 20 '17 at 06:36
  • That is not a valid URI! A URI starts with a protocol. – UninformedUser Feb 20 '17 at 06:48
  • No I mean the graph declaration. `-graph` denotes the IRI of the graph in which you want to load the data. See `tdbloader --help` – UninformedUser Feb 20 '17 at 06:50
  • I'm not sure if the `<.>` namespace is a good idea, that might not be the same. Can you try with `GRAPH ` instead? – Adrian Gschwend Feb 20 '17 at 13:52
  • @AdrianGschwend yes, i tried, still no results. – Charlotte Feb 21 '17 at 01:08
  • To see if you have managed to load the named graphs at all do: SELECT * WHERE {GRAPH ?g { ?s ?p ?o }} This will rule out weird naming of the graphs causing errors and display the graph names. If you still can't see any data query the default graph to see if it ended up there. If you can't figure out the problem I would consider converting the ttl-files into trig prior to loading. – Robin Keskisarkka Mar 21 '17 at 06:59

0 Answers0