我一直在努力(到目前为止没有成功)用“更宽的等于”条件过滤值。也就是说,忽略了变音符号。
select * where {
?s per:surname1 ?t.
bind (fn:starts-with(str(?t),'Maria') as ?noAccent1) .
bind (fn:translate(str(?t),"áéíóú","aeiou") as ?noAccent2) .
} limit 100
到目前为止,我已经尝试过XPath函数fn:contains
,fn:compare
,fn:translate
,fn:starts-with
,但它们似乎都没有工作。
除了链接replace
s之外,还有其他方法可以将校对添加到这些函数中或实现相同的目标吗?
您提到的XPath函数实际上不是SPARQL标准的一部分,因此您发现,您不能依赖它们开箱即用(尽管某些供应商可能会将它们作为附加组件提供)。
但是,GraphDB(基于RDF4J)允许您使用create your own custom functions in SPARQL。这是编写实现org.eclipse.rdf4j.query.algebra.evaluation.function.Function
接口的Java类,并通过将其打包为Java服务提供程序接口(SPI)实现在RDF4J引擎中注册它的问题。
SPARQL和REGEX不支持有效地音译字符映射。如果您想要高效实现,则需要Jeen所描述的自定义RDF4J自定义。
如果您想要快速而肮脏的解决方案,请使用以下代码示例
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX spif: <http://spinrdf.org/spif#>
select * where {
BIND("Mariana" as ?t) .
BIND("Márénísótú" as ?t2) .
BIND (regex(str(?t),'^Maria') as ?noAccent1) .
BIND (spif:replaceAll(
spif:replaceAll(
spif:replaceAll(
spif:replaceAll(
spif:replaceAll(str(?t2),"á","a"),
"é","e")
,"í","i"),
"ó","o"),
"ú","u") as ?noAccent2) .
}