简体   繁体   English

带正则表达式的Java String中的SPARQL请求

[英]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. 我是SPARQL和Jena框架的新手,我想使用正则表达式从Java执行SPARQL查询。 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. 本体变量包含一个OntModel,其名称中带有“ e”。 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. 或提供有关您的用例的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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