从sparql查询结果中过滤掉某些属性 [英] filter out certain properties from sparql query result
问题描述
我正在尝试从sparql查询的结果中滤除某些属性(例如 dbpprop:
的属性)。我正在查询dbpedia sparql endint。
I'm trying to filter out certain properties (e.g dbpprop:
ones) from the result of a sparql query. I'm querying dbpedia sparql endoint.
更准确地说,我想做的事由以下伪代码表示:
More precisely what I'd like to do is expressed by the following pseudo code :
quantity_of_interest, property, value, property_type = sparqlQuery(query)
if property_type == rdf:Property:
pass
else:
return quantity_of_interest, property, value
现在,我随后用一些python过滤掉属性代码,然后使用以下sparql查询:
For now, I filter out the properties afterwards in some python code and I use the following sparql query :
SELECT DISTINCT ?qoi ?property ?value (bif:either(?type=rdf:Property, 0, 1) as ?filter_out)
WHERE {
?qoi a foaf:Person. ?qoi ?property ?value.
OPTIONAL{?property rdf:type ?type }
}
如果 filter_out == 0
我丢弃了整个结果。
If filter_out == 0
I discard the whole result.
有没有办法直接进行sparql查询,每当?type == rdf:Property $ c时,它就会过滤出整个结果$ c>?
Is there a way I can directly make a sparql query which filters out the whole result whenever ?type == rdf:Property
?
推荐答案
您可以过滤出 dbprop:
属性,
You can filter out dbprop:
properties,
我正在尝试从$ b过滤掉某些属性(例如
dbpprop:
的属性) $ b SPARQL查询的结果。我正在查询DBpedia SPARQL端点。
I'm trying to filter out certain properties (e.g.,
dbpprop:
ones) from the result of a SPARQL query. I'm querying the DBpedia SPARQL endpoint.
如果要在结果集中绑定属性,并且要排除那些其结果集中的属性URI以 dbpprop:
前缀开头,您可以使用
If you're binding properties in your result set, and you want to exclude ones whose URI begins with the dbpprop:
prefix, you can do that with
filter(!strstarts(str(?p),str(dbpprop:)))
或者过滤出没有类型 rdf:Property
的属性。
您的伪代码看起来有点不同虽然:
or you can filter out properties that don't have type rdf:Property
.
Your pseudocode looks like it's doing something slightly different though:
quantity_of_interest, property, value, property_type = sparqlQuery(query)
if property_type == rdf:Property:
pass
else:
return quantity_of_interest, property, value
每个属性都可以具有 rdf:Property
类型,因为它是RDF属性的类。 DBpedia可能没有拥有三重
Every property could have the type rdf:Property
, since it's the class of RDF properties. DBpedia might not have the triple
p rdf:type rdf:Property
code>,当然,因此您仍然可以像这样过滤掉内容。如果那是您要执行的操作,则可以使用过滤器不存在{…}
:
for each property p
, of course, so you may still be able to filter things out like this. If that's what you want to do, you can do it with filter not exists { … }
:
filter not exists { ?p rdf:type rdf:Property }
DBpedia,现在就一样了。
事实证明,这些对DBpedia的影响相同,因为没有类型为 rdf:Property
和 ar 还具有 dbpprop:
属性;以下查询返回 0
:
For DBpedia, it's the same right now,
As it turns out, these will have the same effect on DBpedia, since there are no properties that have type rdf:Property
and aren't also dbpprop:
properties; the following query returns 0
:
select (count(*) as ?num) where {
?p a rdf:Property
filter( !strstarts( str(?p), str(dbpprop:) ) )
}
limit 100
,但一种选择是将来更兼容。
I d强烈建议您使用 strstarts
过滤器,而不要使用不存在
。虽然属性的URI不能随时间改变(即URI是恒定的),但有关它的三元组可以更改。因此,如果您过滤掉 dbpprop:
属性,那么您将永远不会意外过滤掉超出预期的内容。但是,如果您滤除类型为 rdf:Property
的内容,那么将来如果更多的 p rdf:type很容易丢失结果rdf:Property
添加了三元组(似乎这样的添加在逻辑上是兼容的)。
but one option is more future compatible.
I'd strongly suggest using the strstarts
filter rather than the not exist
here, though. While the URI of a property can't change over time (i.e., a URI is constant), the triples about it can change. Thus, if you filter out dbpprop:
properties, then you'll never accidentally filter out more than you're expecting. However, if you filter out things that have rdf:Property
as a type, then you can easily lose results in the future if more p rdf:type rdf:Property
triples are added (and it seems like such an addition would be logically compatible).
这篇关于从sparql查询结果中过滤掉某些属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!