sparql-提取URI的最后一部分
我有来自不同域的URI列。例如,
http://comicmeta.org/cbo/category
http://purl.org/dc/terms/hasVersion
http://schema.org/contributor
依此类推。我想在每个此类URI上的最后一个斜杠'/'之后提取最后一部分,即,字符串。
上面的URIS列表中的预期结果:
category
hasVersion
contributor
如何编写 generic sparql查询以从任何给定的URI中提取最后一部分?
这就是我到目前为止尝试的:
SELECT distinct ?s ?x WHERE {
?s ?p ?o .
BIND (STRBEFORE(STRAFTER(STR(?s),"/"), " ") as ?x) .
#To extract the part after the slash '/' and before the end of string indicated by a space ' '.
}
但是,这只返回空字符串“”。
我该如何完成这项工作?有人可以帮我吗?
I have a column of URIs from different domains. Example,
http://comicmeta.org/cbo/category
http://purl.org/dc/terms/hasVersion
http://schema.org/contributor
and so on. I want to extract the last part, i.e, the string after the last slash '/' on each such URI.
Expected results on the above list of URIs:
category
hasVersion
contributor
How do I write a generic SPARQL query to extract this last part from any given URI?
This is what I have tried so far:
SELECT distinct ?s ?x WHERE {
?s ?p ?o .
BIND (STRBEFORE(STRAFTER(STR(?s),"/"), " ") as ?x) .
#To extract the part after the slash '/' and before the end of string indicated by a space ' '.
}
But, this only returns empty strings "".
How can I make this work? Can someone help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
替换
是这样:这仅在最后一个
/
字符之后找到的零件代替整个字符串。但是请注意,由于您的示例,并非所有词汇量都使用/
作为定界符;有些还使用#
。http://www.w3.org/1999/02/02/22-rdf-syntax-ns#type
将变成22-rdf-syntax-ns#代码>
如果您不想要它,则可以使用一些更复杂的东西:
这通常是根据通常是有效的XML名称来选择最长的部分。
Using
REPLACE
is the way:This replaces the whole string with only the part found after the last
/
character. Note however that, due to your examples, not all vocabularies use/
as the delimiter; some also use#
. Something likehttp://www.w3.org/1999/02/22-rdf-syntax-ns#type
will be turned into22-rdf-syntax-ns#type
If you do not want that, you could use something a bit more complicated:
This selects the longest part from the end based on what usually is a valid XML name.