2
votes

I am doing a project under Semantic Web.This is an example of RDF file i am using

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://www.xmlns.com/foaf/0.1">
<rdf:Description>
    <foaf:name>aricent</foaf:name>
   <foaf:url>www.placementhub.net</foaf:url>
  </rdf:Description>
</rdf:RDF>

if user enters "prepare for aricent" for searching the link,I coded in a way to take each value "prepare","for","aricent" and dynamically generate SPARQL query to find the related record.This is the SPARQL query

String queryString ="PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# " + "PREFIX foaf: http://www.xmlns.com/foaf/0.1 " + "SELECT ?name ?url WHERE { ?a foaf:name ?name FILTER regex(?name,'"+ values[i]+"') ?a foaf:url ?url }";

where values[i] is now " prepare" in 1st loop,"for" in 2nd loop and "aricent" in 3rd loop. In such a case if it is executed i will get as

--------------------------------------
| name       | url                   |
======================================
|            |                       |
--------------------------------------

--------------------------------------
| name       | url                   |
======================================
|            |                       |
--------------------------------------

--------------------------------------
| name       | url                   |
======================================
| "aricent" | "www.placementhub.net" |
--------------------------------------

So the resultset is empty(with no values) for "prepare" and "for" and result is got only for "aricent" as it is available in RDF.Can you please tel me how to eliminate(only the table that has value should be shown to the user) the empty resultsets obtained?i used JENA API's.Thank You

1
We'll need a bit more detail. What does your SPARQL query look like? Which tool/API are you using to execute the query and process the result? Also: what exactly do you mean with "the empty resultsets obtained"?Jeen Broekstra
I have edited the question.Thank You for your Kind response.sheba

1 Answers

5
votes

I'm not sure what you mean by eliminate here, but you could do all this in one query, like:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://www.xmlns.com/foaf/0.1>
SELECT ?name ?url
WHERE {
  ?a foaf:name ?name
  FILTER regex(?name,'(prepare|for|aricent)')
  ?a foaf:url ?url
}

Which will return any string that contains any of those words.

Alternatively if you only want strings that have all those words you could do

  FILTER regex(?name,'prepare')
  FILTER regex(?name,'for')
  FILTER regex(?name,'aricent')

It's not clear from your question what you're trying to achieve.