如何按属性的类筛选 SPARQL 查询



是否可以按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 具有一个是欧洲(包括欧洲本身)子类的类型:

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

最新更新