I´m trying to query a repository using SPARQL and Sesame 2.7 but when I run my code I get the following error
org.openrdf.http.client.SesameHTTPClient - Server reports problem: org.openrdf.query.parser.sparql.ast.VisitorException: QName 'viagem:nome' uses an undefined prefix
The problem is that, I have the prefix "viagem" under the Namespaces tab for that repository on openrdf-workbench, also when I use the method getNamespaces() it shows up...
The only way I get the query to run is to add the PREFIX manually on every query, but that sounds wrong...
Is there anything that I´m missing on how to use this properly?
--- Edited with more information
Code not working:
String queryString = "SELECT ?name \n" +
"WHERE {?Aeroporto viagem:nome ?name.\n" +
"?Aeroporto rdf:type viagem:Aeroporto}";
TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
try {
List<String> bindingNames = result.getBindingNames();
while (result.hasNext()) {
BindingSet bindingSet = result.next();
Value firstValue = bindingSet.getValue(bindingNames.get(0));
System.out.println(firstValue);
}
} finally {
result.close();
}
...
This code work if I change queryString to
String queryString = "PREFIX viagem:<http://teste.com.br/tut/Viagem.owl#> SELECT ?name \n" +
"WHERE {?Aeroporto viagem:nome ?name.\n" +
"?Aeroporto rdf:type viagem:Aeroporto}";
I was not sure if I should add the PREFIX for every query that I'm going to execute (if that it´s the normal behavior it´s ok...)
Also if I run the following code I get the prefix and the name correctly
RepositoryResult<Namespace> listaNamespace = meuRepositorio.getConnection().getNamespaces();
while(listaNamespace.hasNext()){
Namespace atual = listaNamespace.next();
System.out.println("Name " + atual.getName() + " Prefix " + atual.getPrefix());
}
the output is:
Name http://www.w3.org/2000/01/rdf-schema# Prefix rdfs
Name http://www.w3.org/2003/11/swrl# Prefix swrl
...
Name http://www.w3.org/1999/02/22-rdf-syntax-ns# Prefix rdf
Name http://teste.com.br/tut/Viagem.owl# Prefix viagem