ontology - Query RDF using SPARQL / Sesame -


i´m trying query repository using sparql , sesame 2.7 when run code following error

org.openrdf.http.client.sesamehttpclient - server reports problem: org.openrdf.query.parser.sparql.ast.visitorexception: qname 'viagem:nome' uses undefined prefix 

the problem that, have prefix "viagem" under namespaces tab repository on openrdf-workbench, when use method getnamespaces() shows up...

the way query run add prefix manually on every query, sounds wrong...

is there i´m missing on how use properly?

--- edited 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);         }         } {             result.close();          } ... 

this code work if change querystring

 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 not sure if should add prefix every query i'm going execute (if it´s normal behavior it´s ok...)

also if run following code prefix , 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 

although sesame stores namespace declarations in repository, there no mechanism in place automatically add these namespaces sparql query. user make sure sparql query correct , complete.

however, workbench application has advanced sparql editor autocomplete support, automatically adds namespace declarations when use prefix. not have type them in manually when using workbench. note convenience of client application, not of actual sparql query engine.

update although, stated above, sesame not read namespace definitions repository when parsing/executing query, allow use prefixed names limited number of standard vocabularies without explicitly declaring them. these 'rdf', 'rdfs', 'owl', 'xsd', 'fn', , 'sesame' prefixes. if use in sparql query without declaring them, sesame's sparql engine automatically replaces them standard namespace prefixes map (note not use namespaces in repository this, uses predefined constants).

however, having said that, it's still practice writer of sparql query make sure query complete. prefix declarations integral part of sparql query, without them query not syntactically valid, , therefore not portable.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -