jeff
jeff

Reputation: 4333

Simple SPARQL query does not return any results

I am just getting up and running with Blazegraph in embedded mode. I load a few sample triples and am able to retrieve them with a "select all" query:

SELECT * WHERE { ?s ?p ?o }

This query returns all my sample triples:

[s=<<<http://github.com/jschmidt10#person_Thomas>, <http://github.com/jschmidt10#hasAge>, "30"^^<http://www.w3.org/2001/XMLSchema#int>>>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<<<http://github.com/jschmidt10#person_Tommy>, <http://github.com/jschmidt10#hasLastName>, "Test">>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<<<http://github.com/jschmidt10#person_Tommy>, <http://www.w3.org/2002/07/owl#sameAs>, <http://github.com/jschmidt10#person_Thomas>>>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<http://github.com/jschmidt10#person_Thomas>;p=<http://github.com/jschmidt10#hasAge>;o="30"^^<http://www.w3.org/2001/XMLSchema#int>]
[s=<http://github.com/jschmidt10#person_Tommy>;p=<http://github.com/jschmidt10#hasLastName>;o="Test"]
[s=<http://github.com/jschmidt10#person_Tommy>;p=<http://www.w3.org/2002/07/owl#sameAs>;o=<http://github.com/jschmidt10#person_Thomas>]

Next I try a simple query for a particular subject:

SELECT * WHERE { <http://github.com/jschmidt10#person_Thomas> ?p ?o }

This query yields no results. It seems that none of my queries for a URI are working. I am able to get results when I query for a literal (e.g. ?s ?p "Test").

The API I am using to create my query is BigdataSailRepositoryConnection.prepareQuery().

Code snippet (Scala) that executes and generates the query:

val props = BasicRepositoryProvider.getProperties("./graph.jnl")
val sail = new BigdataSail(props)
val repo = new BigdataSailRepository(sail)

repo.initialize()

val query = "SELECT ?p ?o WHERE { <http://github.com/jschmidt10#person_Thomas> ?p ?o }"
val cxn = repo.getConnection
cxn.begin()
var res = cxn.
    prepareTupleQuery(QueryLanguage.SPARQL, query).
    evaluate()

while (res.hasNext) println(res.next)
cxn.close()
repo.shutDown()

Upvotes: 1

Views: 419

Answers (1)

Angela Brown
Angela Brown

Reputation: 46

Have you checked the way you filled the database? You might have characters that are getting encoded strangely, or it looks like you might have excess brackets in your objects.

From the print statement, your URI's are printing extra angled brackets. You are likely using:

val subject = valueFactory.createURI("<http://some.url/some/entity>")

when you should be doing this (without angled brackets):

val subject = valueFactory.createURI("http://some.url/some/entity")

Upvotes: 3

Related Questions