SPARQL查询DBLP

3
我正在运行这个查询。
SELECT *
WHERE
{
?s dc:creator ?name .
?s rdf:type swrc:Article .
FILTER regex(str(?name), "Jeffrey", "D.", "Ullman") .
}

我遇到了一个错误:

Encountered " "," ", "" at line 16, column 41.
Was expecting one of:
    <LANGTAG> ...
    <INTEGER_POSITIVE> ...
    <DECIMAL_POSITIVE> ...

那有什么问题吗,我不符合指南吗?我搜索了一下,发现在各种帖子中都有相同的语法。

编辑:

当我查询以下内容时:

SELECT * WHERE { ?s rdf:type swrc:Article . ?s dc:creator ?name . }

我会得到以下结果:

s name <http://dblp.l3s.de/d2r/resource/publications/conf/www/BeszteriV07> [http] <http://dblp.l3s.de/d2r/resource/authors/Istvan_Beszteri> [http]一行,其中第一个URI是?s,第二个是?name

现在我知道确实有一个名为“Jeffrey D. Ullman”的作者,我查询如下:

SELECT * WHERE { ?s rdf:type swrc:Article . ?s dc:creator ?name . FILTER regex(str(?name), "Jeffrey") } LIMIT 10.

然后我会得到类似以下的结果:

s name <http://dblp.l3s.de/d2r/resource/publications/conf/www/LimWPVA07> [http] <http://dblp.l3s.de/d2r/resource/authors/Jeffrey_Scott_Vitter> [http]

因此,问题在于我如何能够匹配“Jeffrey D. Ullman”并查看他写的所有文章。

1
也许Ullman的URI没有dc:creator属性。你可以尝试str(<http://dblp.l3s.de/d2r/resource/authors/Jeffrey_D._Ullman>。 - scotthenninger
@scotthenninger 是的,我调查了您的建议,确实得到了结果。谢谢。 - user3725561
2个回答

5
你的正则表达式函数语法不正确,请参考SPARQL1.1规范。请注意,regex函数需要精确地传入两个或三个参数,第一个参数是文本,第二个参数是模式,最后一个参数是可选的字符串,包含标志。

17.4.3.14 REGEX

xsd:boolean  REGEX (string literal text, simple literal pattern) 
xsd:boolean  REGEX (string literal text, simple literal pattern, simple literal flags)

4

对 SPARQL 进行背景研究是一个非常好的主意。在这里明确指出问题,正则表达式将字符串与正则表达式进行匹配。因此下面的内容:

FILTER regex(str(?name), "Jeffrey D\\. Ullman") .

...将匹配 "Jeffrey D. Ullman"。以下是:

FILTER regex(str(?name), "Ullman") .

...将匹配"Jeffrey D. Ullman"和任何包含"Ullman"的?name。这个过滤器:

FILTER regex(str(?name), "Ullman$") .

这个过滤器将匹配任何以"Ullman"结尾的字符串。而这个过滤器:

FILTER regex(str(?name), "^Jeffrey.*Ullman$") .

...将匹配任何以“Jeffrey”开头,以“Ullman”结尾,并在中间包含任何字符的字符串。

等等...


1
"Jeffrey D. Ullman"将匹配"Jeffrey D. Ullman"。实际上它会匹配很多东西,比如"Jeffrey DX Ullman"等,因为.在正则表达式中是通配符。 - Joshua Taylor
1
当然。已经修复了。 - scotthenninger
@chrisis 我会尽快编辑问题,以便向您展示我正在处理的完整问题。到目前为止,您的答案非常有帮助。 - user3725561
FILTER regex(str(?name), "Jeffrey D\\. Ullman") . 返回0个结果。 - user3725561
可能取决于您的系统如何转义“.”。尝试使用单个反斜杠或查找正在使用的正则表达式语法。 - scotthenninger

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接