Robert jardonneau
Robert jardonneau

Reputation: 444

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 ?

Upvotes: 1

Views: 286

Answers (1)

Abecee
Abecee

Reputation: 2393

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.

Upvotes: 2

Related Questions