简体   繁体   中英

SPARQL request in Java String with regex

I'm new to SPARQL and Jena framework, and I would like to perform a SPARQL query from Java with a regular expression. Here is my code :

String queryString = "select ?a where { filter regex(?a, 'e', 'i') }";

Query query = QueryFactory.create(queryString);

try (QueryExecution qexec = QueryExecutionFactory.create(query, ontology)) {
    ResultSet results = qexec.execSelect() ;
    for ( ; results.hasNext() ; )
    {
        QuerySolution soln = results.nextSolution() ;
        System.out.println("a : " + soln.get("a").toString());
    }
}

Ontology variable contains an OntModel that has concept with 'e' in their names. I would like this request to retrieve those concepts, however this code displays nothing while it does if I replace the regex by simpler stuff. I do not understand what is wrong with my request, could anyone help me ?

The way I see it, you have nothing to apply a filter to. Try along

PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
SELECT ?a
WHERE
{ ?o skos:prefLabel ?a .
  FILTER REGEX(?a, 'e', 'i').
}
ORDER BY ?a

or provide more detail about your use case.

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