我(几乎)遇到与here相同的问题。但我无法弄清楚如何将它应用于我的问题。我想将SPARQL查询转换为其algebra expression。所以示例代码:
Query query = QueryFactory.create(args[0]);
Op op = Algebra.compile(query) ;
System.out.println(op);
然而,as Joshua said:Virtuoso接受非标准SPARQL而Jena不接受..错误是:
Exception in thread "main" org.apache.jena.query.QueryParseException: Encountered " "<" "< "" at line 1, column 14.
手动更正查询并不是真正的解决方案,因为我想通过几百个查询来执行此操作...感谢您的帮助
修改
示例查询:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE
{
{?city rdfs:label 'Tapiramutá'@en.}
UNION
{ ?alias <http://dbpedia.org/property/redirect> ?city;
rdfs:label 'Tapiramutá'@en. }
UNION
{?alias <http://dbpedia.org/property/disambiguates> ?city;
rdfs:label 'Tapiramutá'@en. }
OPTIONAL { ?city <http://dbpedia.org/ontology/abstract> ?abstract}
OPTIONAL { ?city geo:lat ?latitude; geo:long ?longitude}
OPTIONAL { ?city foaf:depiction ?image }
OPTIONAL { ?city rdfs:label ?name }
OPTIONAL { ?city foaf:homepage ?home }
OPTIONAL { ?city <http://dbpedia.org/ontology/populationTotal> ?population }
OPTIONAL { ?city <http://dbpedia.org/ontology/thumbnail> ?thumbnail } FILTER (langMatches( lang(?abstract), 'en'))}