相关疑难解决方法(0)

SPARQL:获取某个类的子类的所有实体

我将在SPARQL中获取C的C类和子类(直接或间接)的所有实例.

我可以用这种方式得到C的所有直接子类:

SELECT ?entity
WHERE {
  ?subclass rdfs:subClassOf :C .
  ?entity rdf:type ?subclass .
}
Run Code Online (Sandbox Code Playgroud)

但我不能得到间接子类的实例,也不能得到任何C的实例.

据我所知(我已经预先计算了它们)所有子类(C的直接和间接),我可以构建一个动态查询,是否可以构建如下的查询?

SELECT ?entity
WHERE {
  ?entity rdf:type in <list>.
}
Run Code Online (Sandbox Code Playgroud)

谢谢大家.

编辑:

我刚刚解决了它,即使是以一种不优雅的方式.

SELECT ?entity
WHERE {
  { ?entity rdf:type :C }
  UNION { ?entity rdf:type :SubClass1 }
  UNION { ?entity rdf:type :SubClass2 }
  UNION { ?entity rdf:type :SubClass3 }
}
Run Code Online (Sandbox Code Playgroud)

entity subclass instance sparql

11
推荐指数
2
解决办法
2万
查看次数

检索OWL交集类隐含的超类

OWL本体可以具有类A,B和C以及公理(在DL表示法中):

A⊑(B⊓C)

或者近似曼彻斯特OWL语法:

subClassOf(B C)

从逻辑上讲,A是B的子类,A是C的子类,但是三元组

A rdfs:subClassOf B
A rdfs:subClassOf C
Run Code Online (Sandbox Code Playgroud)

不一定存在于OWL本体的RDF序列化中.例如,考虑Protégé中这个非常简单的本体及其在RDF/XML和Turtle中的RDF序列化:

在此输入图像描述

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://stackoverflow.com/q/19924861/1281433/sample.owl#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl"/>
  <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#C"/>
  <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#B"/>
  <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#A">
    <rdfs:subClassOf>
      <owl:Class>
        <owl:intersectionOf rdf:parseType="Collection">
          <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#B"/>
          <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#C"/>
        </owl:intersectionOf>
      </owl:Class>
    </rdfs:subClassOf>
  </owl:Class>
</rdf:RDF>
Run Code Online (Sandbox Code Playgroud)
@prefix :      <http://stackoverflow.com/q/19924861/1281433/sample.owl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://stackoverflow.com/q/19924861/1281433/sample.owl>
        a       owl:Ontology .

:B      a       owl:Class .

:C      a       owl:Class .

:A      a                owl:Class ;
        rdfs:subClassOf …
Run Code Online (Sandbox Code Playgroud)

java rdf semantic-web owl sparql

3
推荐指数
1
解决办法
1666
查看次数

Sparql查询一个类的子,孙子,..

我有一个我在Protege中构建的猫头鹰文件.什么是sparql查询,它将选择类的所有子类以及这些子类的所有子类,依此类推(广度优先搜索排序方式)?

owl sparql protege4 protege

3
推荐指数
1
解决办法
3688
查看次数

标签 统计

sparql ×3

owl ×2

entity ×1

instance ×1

java ×1

protege ×1

protege4 ×1

rdf ×1

semantic-web ×1

subclass ×1