0

I am doing project in semantic web where i use SPARQL to query rdf data. I used java in netbeans and my problem is my program runs,inputs the rdf file and the query executes but the WHERE area of my query is not considered. (i.e) i get a empty table as output

Can you please tel me any suggestions of SPARQL syntax in JAVA to retrieve all name,phone number from rdf file

1
  • 1
    can you post some sample data and also an example of one of those queries ? Commented Aug 30, 2011 at 17:17

1 Answer 1

1

"WHERE area of my query is not considered. (i.e) i get a empty table as output"

I doubt the WHERE clause is not being considered. An empty table suggests a) you have no data or b) your query has no matches.

Retrieving all names and phone number depends on the vocabulary used, but the most common by far is foaf:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name, ?number
WHERE
{
    ?person foaf:name ?name .
    ?person foaf:phone ?number .
}

We need more information, so here's some generic advice:

  1. Try SELECT * WHERE { ?s ?p ?o }. Is that getting results? If not, try...
  2. Try SELECT * WHERE { graph ?g { ?s ?p ?o } }. Is that getting results?

If neither are working you may have issues with you data. If only the second gets result you check you are querying graphs.

This will give you a good idea about what you have loaded either way. If it looks ok:

  1. Remove an element of your WHERE clause.
  2. If you still get no results go to 1.
  3. If you get results you have found an issue with your query.

You can also try replacing terms with variables. Working this way might help track down which elements are causing the query to fail.

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you so much for your reply sir.Tried with the first query and i got the output sir.But the second query gives me only a empty table.and tried various queries,but empty table is only got.Here is my rdf file <?xml version="1.0"?> <rdf:RDF xmlns:rdf="w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="resume.fake/foaf#"> <rdf:Description rdf:about="resume.fake/foaf/Sheba"> <foaf:name>Sheba</foaf:name> <foaf:phne>8872443601</foaf:phne></rdf:Description> </rdf:RDF>
Problem is in my java code i hope so.here is my java code sir.please help me. String queryString ="PREFIX rdf: <w3.org/1999/02/22-rdf-syntax-ns#> " +"PREFIX foaf: <resume.fake/foaf/#> " + "SELECT ?name ?number WHERE { ?x foaf:name ?name . ?x foaf:phone ?number .}"; Query query = QueryFactory.create(queryString);QueryExecution qe = QueryExecutionFactory.create(query,model);ResultSet results = qe.execSelect();ResultSetFormatter.out(System.out, results, query);
You spelled 'phone' wrong. <foaf:phne> should be <foaf:phone> in your rdf file.
Changed and tried it sir.But i still get an empty table in output.
You have the wrong prefix for foaf, and because the one you have is relative your queries will break. Use xmlns.com/foaf/0.1
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.