rdf - 通过正则表达式查询主题或谓词

标签 rdf sparql

鉴于此RDF:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>

<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about="Fadi" xml:startTime="00:01:38" xml:endTime="00:01:39">
    <ns0:eat xmlns:ns0="http://example.org/">Apple</ns0:eat>
  </rdf:Description>
</rdf:RDF>

当我执行此SPARQL查询时
SELECT *
WHERE {
  ?s ?p ?o . 
  FILTER (regex(?o, 'Apple','i'))
}

我得到主题和谓词:
s: http://example.org/Fadi , p: http://example.org/eat .

但是当我执行
SELECT *
WHERE {
  ?s ?p ?o .
  FILTER (regex(?s, 'Fadi','i'))
}

要么
SELECT *
WHERE {
  ?s ?p ?o .
  FILTER (regex(?s, 'http://example.org/Fadi','i'))
}

我什么都没有。如何查询主语或谓语?
如何查询startTimeendTime

最佳答案

?s是一个URI,而正则表达式适用于字符串。使用 str 函数来获取字符串:

FILTER (regex(str(?s), 'Fadi','i'))

关于rdf - 通过正则表达式查询主题或谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16250832/

相关文章:

sparql - 令人困惑的可选 - 消失的记录

namespaces - 为什么在查询本体时我们必须加载本体,还要提供它的命名空间?

SPARQL:拥有女市长的最大城市

SPARQL 和 DBPedia - 从 wiki 页面重定向名称获取基本 url

python - 强制 rdflib 定义命名空间

rdf - skos :ConceptScheme and skos:Collection? 有什么区别

sparql - 这个 SPARQL 查询可以简化吗?

view - Sparql View - 查询

html - 使用 SPARQL 从 HTML 页面查询元数据不返回任何内容

odata - OData与语义Web/链接数据的比较