[英]filter out certain properties from sparql query result
I'm trying to filter out certain properties (eg dbpprop:
ones) from the result of a sparql query. 我正在尝试从sparql查询的结果中滤除某些属性(例如
dbpprop:
这些)。 I'm querying dbpedia sparql endoint. 我正在查询dbpedia sparql endint。
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
For now, I filter out the properties afterwards in some python code and I use the following sparql query : 现在,我随后使用一些python代码过滤掉属性,并使用以下sparql查询:
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 }
}
If filter_out == 0
I discard the whole result. 如果
filter_out == 0
我将丢弃整个结果。
Is there a way I can directly make a sparql query which filters out the whole result whenever ?type == rdf:Property
? 有没有一种方法可以使我直接进行sparql查询,每当
?type == rdf:Property
时,该查询就过滤掉整个结果?
This one is working for me at http://dbpedia.org/snorql/?query= 可以在http://dbpedia.org/snorql/?query=
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?qoi ?property ?value
WHERE {
?qoi a foaf:Person.
?qoi ?property ?value.
OPTIONAL{
?property rdf:type ?type
FILTER( ?type != "rdf:Property" ) }
}
LIMIT 100
I am not sure if this is the answer you are looking for 我不确定这是否是您要找的答案
dbprop:
properties, dbprop:
属性, I'm trying to filter out certain properties (eg,
dbpprop:
ones) from the result of a SPARQL query.我正在尝试从SPARQL查询的结果中滤除某些属性(例如
dbpprop:
这些)。 I'm querying the DBpedia SPARQL endpoint.我正在查询DBpedia SPARQL端点。
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 如果要在结果集中绑定属性,并且要排除URI以
dbpprop:
前缀开头的dbpprop:
,则可以使用
filter(!strstarts(str(?p),str(dbpprop:)))
rdf:Property
. rdf:Property
类型的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
Every property could have the type rdf:Property
, since it's the class of RDF properties. 每个属性都可以具有
rdf:Property
类型,因为它是RDF属性的类。 DBpedia might not have the triple DBpedia中可能没有三
p rdf:type rdf:Property
for each property p
, of course, so you may still be able to filter things out like this. 当然,对于每个属性
p
,您仍然可以像这样将其过滤掉。 If that's what you want to do, you can do it with filter not exists { … }
: 如果这是您要执行的操作,则可以使用
filter not exists { … }
:
filter not exists { ?p rdf:type rdf:Property }
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; 事实证明,这些对DBpedia具有相同的效果,因为不存在类型为
rdf:Property
, 也不是 dbpprop:
属性; the following query returns 0
: 以下查询返回
0
:
select (count(*) as ?num) where {
?p a rdf:Property
filter( !strstarts( str(?p), str(dbpprop:) ) )
}
limit 100
I'd strongly suggest using the strstarts
filter rather than the not exist
here, though. 我强烈建议使用
strstarts
过滤器,而不是这里not exist
过滤器。 While the URI of a property can't change over time (ie, a URI is constant), the triples about it can change. 虽然属性的URI不能随时间改变(即URI是恒定的),但有关它的三元组可以更改。 Thus, if you filter out
dbpprop:
properties, then you'll never accidentally filter out more than you're expecting. 因此,如果您滤除
dbpprop:
属性,那么您绝不会意外滤除超出预期的内容。 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). 但是,如果您过滤掉以
rdf:Property
作为类型的内容,那么将来如果添加更多p rdf:type rdf:Property
三元组,您很容易会丢失结果(看来这种添加在逻辑上是兼容的) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.