繁体   English   中英

如何通过属性的类过滤SPARQL查询

[英]How to filter a SPARQL query by a property's class

是否可以通过其属性之一的类来查询过滤器SPARQL查询? 我有一个描述电影的本体,我希望展示所有在欧洲拍摄的电影。

当前的SPARQL查询如下:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX cinema: <http://example.com/ontologies/cinemachain#>
SELECT ?film ?location
    WHERE { 
        ?film rdf:type cinema:Film .
        ?film cinema:wasFilmedAt ?location .
        FILTER(?location rdfs:subClassOf cinema:Europe) .

}

where子句的前两行为我提供了所有电影及其位置的列表。 如果位置是Cinema:Europe的子类,我如何使用过滤器返回结果?

在这种特定的本体中,Cinema:Europe是Cinema:Location的子类。 这样一来,我们就可以轻松地按洲识别特定位置。 对于此筛选器,我想查找所有具有欧洲成员位置的电影。 您知道如何使用SPARQL做到这一点吗?

好的,命名约定有点不寻常,但是我们可以使用它。 您只需要要求?location的类型是Europe(包括Europe本身)的子类即可:

select ?film ?location where {
  ?film rdf:type cinema:Film ;
        cinema:wasFilmedAt ?location .
  ?location rdf:type/rdfs:subClassOf* cinema:Europe .
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM