我有这个我的rdf文件,我试图从特定的命名空间获取所有三元组 ' NS1'
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ns1="http://www.w3.org/TR/rdf-schema/#"
xmlns:property="http://www.SyrianDNA.com/property#"
xmlns:info="http://www.SyrianDNA.com/info#">
<rdf:Description rdf:about="http://www.SyrianDNA.com/resource/monuments">
<ns1:be rdf:resource="http://www.SyrianDNA.com/resource/Syria"/>
<ns1:refer rdf:resource="http://www.SyrianDNA.com/resource/glass"/>
<property:subjectType>thing</property:subjectType>
<property:location>syria</property:location>
<info:Title>umayyad_architecture</info:Title>
<info:Img_URL>
http://en.wikipedia.org/wiki/Umayyad_architecture#/media
/File:110409_046.jpg</info:Img_URL>
<info:Page_URL>
http://en.wikipedia.org/wiki/Umayyad_architectureeee</info:Page_URL>
</rdf:Description>
</rdf:RDF>
我尝试这个sparql查询但在尝试从以下输入进行标记时抛出异常&#34;意外的流结束:
String q = @"PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dc:<http://purl.org/dc/elements/1.1/>
PREFIX ns1:<http://www.w3.org/TR/rdf-schema/#>
PREFIX property:<http://www.SyrianDNA.com/property#>
PREFIX info:<http://www.SyrianDNA.com/info#>
SELECT ?s ?o ?p
where { ?s ?p ?o
" +
" FILTER((\"http://www.w3.org/TR/rdf-schema/#\")<STR(?s)).}";
答案 0 :(得分:1)
问题在于写FILTER((\"http://www.w3.org/TR/rdf-schema/#\")<STR(?s))
。您不能拥有大于命名空间的字符串。如果要根据命名空间进行过滤,则需要查看要过滤的实例的内容,然后编写如下内容:
select distinct *
where{
?s ?p ?o
filter(STRSTARTS(str(?s), "http://www.w3.org/TR/rdf-schema/"))
}
甚至是正则表达式:
select distinct *
where{
?s ?p ?o
FILTER regex(str(?s), "^http://www.w3.org/TR/rdf-schema/") .
}