[英]Writing a SPARQL query with Jena, FILTER and REGEX
I wrote I SPARQL
query with JENA
with the REGEX
: /^name$/i
(Actually name
is a String variable that could be any value, with spaces or not, it's received as a parameter of the method). 我用REGEX
用JENA
编写了我的SPARQL
查询: /^name$/i
(实际上name
是一个String变量,可以是任何值,带或不带空格,它作为方法的参数接收)。
Here's the String query: 这是String查询:
String authorquery = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX dc: <http://purl.org/dc/elements/1.1/> " +
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT " +
"?URIAutor WHERE { " +
"?URIAutor foaf:name ?Autor." +
"FILTER (regex(?Autor, \"" + "/^" + name + "$/" + "\", 'i' ) ).}";
That isn't giving me an exception, but isn't returning me results when I write a name that I'm sure is on the Database. 这并没有给我一个例外,但是当我写一个我确定在数据库中的名字时,并没有给我返回结果。 That's what I want with this query: I have the name "Agatha Christie" on the database. 这就是我要查询的内容:我在数据库上的名称为“ Agatha Christie”。 If name=Agatha
I would like the query to return nothing. 如果name=Agatha
我希望查询不返回任何内容。 I'd like it only to return me the URI from the author named "Agatha Christie" if name="Agatha Christie"(can be case insentive). 我只想返回我名为“ Agatha Christie”的作者的URI(如果名称为“ Agatha Christie”(可以区分大小写))。 The same holds for the names "Bill Clinton" and "Bill Gates", if name=Bill
I wouldn't like to find both URIs, but the query should return no results. 名称“ Bill Clinton”和“ Bill Gates”的情况相同,如果name=Bill
我不想同时找到这两个URI,但是查询不返回任何结果。 The result should come for "Bill Clinton" only if name="Bill Clinton"
. 仅当name="Bill Clinton"
,结果才应为name="Bill Clinton"
。
I don't know if the problem is with the REGEX or with turning the REGEX into a String with a variable in the middle. 我不知道问题出在REGEX还是将REGEX变成一个在中间带有变量的字符串。
Could you help me? 你可以帮帮我吗?
Don't put /.../
around the regex string. 不要在正则表达式字符串中加上/.../
。 ^name$
will do. ^name$
可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.