DBpedia/Virtuoso SPARQL 应使用哪种风格的正则表达式?
What flavor of regex should be used with DBpedia/Virtuoso SPARQL?
我尝试使用 FILTER 仅匹配完整字符串,而不匹配 sparql 中的子字符串。
我正在查询 DBPedia (which is hosted on Virtuoso)。
我不太确定 SPARQL 是否支持字界,看看如何使用
FILTER(regex(?name, "V", "i"))
将找到包含 V、IV、VI、VII 等的那些。
现在,我尝试使用
FILTER(regex(?name, "\<V\>", "i"))
在端点上生成编译错误
Virtuoso 37000 Error SP030: SPARQL compiler, line 0: Bad escape sequence in a short double-quoted string at '"\'
我也试过
FILTER(regex(?name, "\bV\b", "i"))
虽然这个查询被接受了,但它没有 return 任何结果,我猜这是因为它将它作为退格而不是字界。
我试过寻找它使用的味道,我唯一发现的是它使用 XQuery 1.0 and XPath 2.0 Functions and Operators
感谢您的宝贵时间!
字界与 \b
一起使用,请参阅
SELECT DISTINCT ?s ?l WHERE {
?s a <http://dbpedia.org/ontology/SoccerClub> ;
<http://www.w3.org/2000/01/rdf-schema#label> ?l
FILTER(LANGMATCHES(LANG(?l),'en'))
FILTER(REGEX(STR(?l), "\bD", "i"))
} LIMIT 100
有returns个英文名称以"d"开头的足球俱乐部
ETA:Virtuoso 开发人员报告说它使用 Perl Compatible Regular Expressions。
SPARQL 1.1 的 regex 函数在标准的 17.4.3.14 REGEX 中描述:
Invokes the XPath fn:matches function to match text against a regular expression pattern. The regular expression language is defined in XQuery 1.0 and XPath 2.0 Functions and Operators section 7.6.1 Regular Expression Syntax.
通过一些链接,您将到达正则表达式的 XML 模式定义,位于 Appexndix F: Regular Expressions。如果您在该文档中查找多字符转义,您会发现:
- \w
[#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}] (all characters except the set
of "punctuation", "separator" and "other" characters)
- \W
[^\w]
当我阅读时,我认为 \W 是您正在寻找的单词分隔符。
我尝试使用 FILTER 仅匹配完整字符串,而不匹配 sparql 中的子字符串。
我正在查询 DBPedia (which is hosted on Virtuoso)。
我不太确定 SPARQL 是否支持字界,看看如何使用
FILTER(regex(?name, "V", "i"))
将找到包含 V、IV、VI、VII 等的那些。
现在,我尝试使用
FILTER(regex(?name, "\<V\>", "i"))
在端点上生成编译错误
Virtuoso 37000 Error SP030: SPARQL compiler, line 0: Bad escape sequence in a short double-quoted string at '"\'
我也试过
FILTER(regex(?name, "\bV\b", "i"))
虽然这个查询被接受了,但它没有 return 任何结果,我猜这是因为它将它作为退格而不是字界。
我试过寻找它使用的味道,我唯一发现的是它使用 XQuery 1.0 and XPath 2.0 Functions and Operators
感谢您的宝贵时间!
字界与 \b
一起使用,请参阅
SELECT DISTINCT ?s ?l WHERE {
?s a <http://dbpedia.org/ontology/SoccerClub> ;
<http://www.w3.org/2000/01/rdf-schema#label> ?l
FILTER(LANGMATCHES(LANG(?l),'en'))
FILTER(REGEX(STR(?l), "\bD", "i"))
} LIMIT 100
有returns个英文名称以"d"开头的足球俱乐部
ETA:Virtuoso 开发人员报告说它使用 Perl Compatible Regular Expressions。
SPARQL 1.1 的 regex 函数在标准的 17.4.3.14 REGEX 中描述:
Invokes the XPath fn:matches function to match text against a regular expression pattern. The regular expression language is defined in XQuery 1.0 and XPath 2.0 Functions and Operators section 7.6.1 Regular Expression Syntax.
通过一些链接,您将到达正则表达式的 XML 模式定义,位于 Appexndix F: Regular Expressions。如果您在该文档中查找多字符转义,您会发现:
- \w [#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}] (all characters except the set of "punctuation", "separator" and "other" characters)
- \W
[^\w]
当我阅读时,我认为 \W 是您正在寻找的单词分隔符。