简体   繁体   中英

Sparql with Java Jena

I'm using next query in wikidata query service:

PREFIX wd: <http://www.wikidata.org/entity/> 
PREFIX wdt: <http://www.wikidata.org/prop/direct/>  
PREFIX xsd: <www.w3.org/2001/XMLSchema#>  
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>  

select ?lexemeId ?lemma WHERE { 
?lexemeId <http://purl.org/dc/terms/language> wd:Q1860.
  ?lexemeId wikibase:lemma ?lemma.
FILTER (regex(?lemma, '^bank.*'))
}

It works fine when executing at https://query.wikidata.org/ but, if trying using Java Jena, it fails, cause:

Exception in thread "main" org.apache.jena.query.QueryParseException: Line 7, column 11: Unresolved prefixed name: wikibase:lemma

It can't resolve wikibase as a prefix. Any clue? Thx in advance, David.

When you use their SPARQL query page a number of prefixes are pre-declared, including wikibase. When querying the endpoint remotely these have to be declared. So use PREFIX wikibase: <http://wikiba.se/ontology#> in your query.

A list of prefixes is available in the wiki

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM