Dear All,
I already solved the issue using the manipulations with Java code. However,
the question how to solve it in a SPARQL query is still open.
My solution with Java code is:
String result:
while (results.hasNext()) {
QuerySolution solution = results.next();
result = solution.get("?room").toString();
result = result.substring(result.indexOf("#") + 1,
result.length());
System.out.println(result);
}
qe.close();
Best,
Darius
2013/8/20 Darius Miliauskas <[email protected]>
> Subject: The Better Looking Output After the SPARQL Query in Java Code
> To: [email protected]
>
>
> Dear Sir or Madam,
>
> I am using the SPARQL query in Java (actually, NetBeans). The query works
> fine, however, the results are outputted not in the nice form.
>
> The example of my code (Java) is the following:
>
> String queryString2 ="PREFIX base: <
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#>"
> + "PREFIX rdf: <
> http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
> + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
> + "PREFIX owl: <http://www.w3.org/2002/07/owl#>"
> + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>"
> + "SELECT ?person ?room WHERE { ?person a base:Person.
> ?room a base:Room."
> + "FILTER regex(STR(?person), \"Ana\") }"
> + "ORDER BY DESC (?person)";
> Query query = QueryFactory.create(queryString2);
> QueryExecution qe = QueryExecutionFactory.create(query, model);
> com.hp.hpl.jena.query.ResultSet results = qe.execSelect();
> ResultSetFormatter.out(System.out, results, query);
> ResultSetFormatter.asText(results, query);
> qe.close();
>
> I get the results in the following form:
>
> ----------------------------------------------------------------------------------------------------
> | person | room
> |
>
> ====================================================================================================
> | base:Ana | <
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Rue_de_Mont_Blanc,_Geneva>
> |
>
> ----------------------------------------------------------------------------------------------------
>
> Is there any possibility in SPARQL to cut or substring these additional
> parts ("Ana instead of "base: Ana" or "Rue_de_Mont_Blanc,_Geneva" instead
> of the "<
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Rue_de_Mont_Blanc,_Geneva>")?
> I tried FILTER (SUBSTR(?person, 4)) in the query, but it did not give me
> the desired results. Or it is recommended to do in Java? How to do it?
>
>
> Thanks for any suggestions,
>
> Darius Miliauskas
>
>
>
>
>
>