0

FirstTestingClass.java

package com.mycompany.sparqlwithjena1;

import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.ResultSetFormatter;
import org.apache.jena.sparql.engine.http.QueryEngineHTTP;

public class FirstTestingClass {
public static void main(String[] args)
{
    sparqlQuery();
}
static void sparqlQuery()
{
    String url4= "http://dbpedia.org/sparql/";
    String queryString =
           "PREFIX ol: <http://www.openlinksw.com/schemas/virtrdf#> "+
            " SELECT ?person ?x"+
            " WHERE { "+
            " ?person a ?x . "+
            //" FILTER ( regex( str(?person) , 'resource' ,'i') ) ."+
            " }";
    Query query = QueryFactory.create(queryString);

    QueryEngineHTTP qe= new QueryEngineHTTP(url4,queryString);

    ResultSet result = qe.execSelect();
      ResultSetFormatter.out(result, query);
      qe.close();
}
}

This gives this kind of output

| person | x |

| http://www.openlinksw.com/virtrdf-data-formats#default-iid | ol:QuadMapFormat |
| http://www.openlinksw.com/virtrdf-data-formats#default-iid-nullable | ol:QuadMapFormat |

I only pasted two tuples of output there were more than 100 tuples in output.So Why this is happening?.Is It because of automatically URL dereferencing?.

I try query for same URL(=url4) on librdf.org .It gives only one tuple as output.

I also try to check triplets form on rdf-translator.appspot.com for URL(=url4) by converting automatically to N3 form.It also show there should be only one tuple for given query.

Please help where I did wrong? I am beginner please explain it.

Badman
  • 407
  • 5
  • 17

2 Answers2

0

You're asking Jena to run a SPARQL query against the endpoint at http://dbpedia.org/sparql. You can go to that endpoint manually in a web browser and run your same query. You get lots of results when you run your query there. You asked about some other places, like

I try query for same URL(=url4) on librdf.org .It gives only one tuple as output.

I'm not sure what exactly you mean by that. Do you mean you ran the same query on some endpoint that they support? If you did that, of course you'd get different results, because it's a different endpoint.

For comparison, if you run the same SQL query on different databases, you can very well get different results, because the data in those databases is different. Or if you ask different people, "How many siblings do you have?" you'll get different answers, because different people have different numbers of siblings.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • The funny thing is that the query is the same as `?s a ?o` just with variables that have some meaning for a user but for sure not the triple strore – UninformedUser Aug 09 '16 at 17:01
  • @Joshua Taylor @{AKSW} This is my output for above java code in netbeans for url4 – Badman Aug 10 '16 at 05:14
  • This output is different from Joshua Output while endpoint is same.If automatically dereferencing is not happening then why there are lots of outputs. – Badman Aug 10 '16 at 05:22
  • Joshua you gave me result of url =http://dbpedia.org not for url = http://dbpedia.org/sparql .So its your mistake this is actual output [link](http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org%2Fsparql&query=PREFIX+ol%3A+%3Chttp%3A%2F%2Fwww.openlinksw.com%2Fschemas%2Fvirtrdf%23%3E+%0D%0ASELECT+%3Fperson+%3Fx+%0D%0AWHERE+%7B+%0D%0A%3Fperson+a+%3Fx+.+%0D%0A+%7D&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&debug=on) – Badman Aug 10 '16 at 05:32
  • @Badman see my answer, those triples are Virtuoso internal and might be omitted if the default graph is set. And also understand that your query does **not** return persons only. – UninformedUser Aug 10 '16 at 07:52
  • @Badman I'm not sure exactly you mean. URL4 in your code is the endpoint that you're sending the query to, and the value in your code is `http://dbpedia.org/sparql/`. – Joshua Taylor Aug 10 '16 at 12:59
  • @JoshuaTaylor I think he is still mixing up the URL to the remote SPARQL service and the concept of graphs in SPARQL. And what he wants to achieve is not possible from my point of view as DBpedia classes aren't stored as separate graphs. – UninformedUser Aug 12 '16 at 08:04
0

The answer to your question is:

No, Jena is not automatically dereferencing URIs. Please have a look at your SPARQL query. It is similar to

SELECT ?s ?o WHERE {
   ?s a ?o .
}

That you give the variables human readable names does not mean that the semantics is recognized when processing the query. The triples that you are asking for with your query are all triples that have rdf:type as predicate. And the triples that you have shown are some Virtuoso internal triples - the triples store on which DBpedia is deployed. It might be solved when you set as default graph http://dbpedia.org in your Jena code:

qe.addDefaultGraph("http://dbpedia.org");
UninformedUser
  • 8,397
  • 1
  • 14
  • 23