java - 查询所有 "AnnotationAssertions"的类(class)/个人

标签 java rdf sparql owl

我正在尝试查询与类/个人相关的所有 AnnotationAssertion。

下面是我的来源片段:

        <AnnotationAssertion>
            <AnnotationProperty abbreviatedIRI="rdfs:comment"/>
            <IRI>#Car</IRI>
            <Literal xml:lang="en" datatypeIRI="&rdf;PlainLiteral">A car has four tyres</Literal>
        </AnnotationAssertion>
        <AnnotationAssertion>
            <AnnotationProperty IRI="http://www.w3.org/2004/02/skos/core#definition"/>
            <IRI>#car</IRI>
            <Literal xml:lang="en" datatypeIRI="&rdf;PlainLiteral">a road vehicle, typically with four wheels, powered by an internal combustion engine and able to carry a small number of people.</Literal>
        </AnnotationAssertion>
        <AnnotationAssertion>
            <AnnotationProperty IRI="http://www.w3.org/2004/02/skos/core#example"/>
            <IRI>#car</IRI>
            <Literal xml:lang="en" datatypeIRI="&rdf;PlainLiteral">Audi</Literal>
        </AnnotationAssertion>
 etc..

我正在尝试查询与此类/个体关联的 AnnotationProperties 及其 AnnotationAssertions 列表。

SPARQL-DL API提供通过

查询注释属性的可能性
Annotation(a, b, c)

任何查询 AnnotationAssertions 的指针都会非常有帮助。

最佳答案

您在问题中提到了 SPARQL-DL,但这也被标记为 ,并且简单的 SPARQL 中的答案并不太复杂。这将类似于:

prefix  owl: <http://www.w3.org/2002/07/owl#>

select ?s ?p ?o where { 
  ?s ?p ?o .
  ?p a owl:AnnotationProperty .
}

但是,您在这里可能遇到的困难是,可能并非每个注释属性都被实际声明。这会让事情变得更加困难,但是您可以通过询问所有三元组来尝试解决这个问题,除了那些属性是已知的 ObjectProperty 或 DatatypeProperty 的三元组,以及那些在 OWL 到 RDF 映射中使用的三元组(以 rdf 开头的属性:或 owl: 和某些 rdfs: 属性)。例如,

prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?s ?p ?o where {
  ?s ?p ?o .

  #-- don't include object or datatype properties    
  filter not exists {
    values ?type { owl:ObjectProperty owl:DatatypeProperty }
    ?p a ?type 
  }

  #-- don't include properties from rdf: or owl: namespaces  
  filter( !strstarts( str(?p), str(rdf:) ) )
  filter( !strstarts( str(?p), str(owl:) ) )

  #--  don't include rdfs: properties used in OWL to RDF mapping
  filter( ?p not in ( rdfs:range, rdfs:domain, rdfs:subClassOf, rdfs:subPropertyOf ) )
}

关于java - 查询所有 "AnnotationAssertions"的类(class)/个人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26656608/

相关文章:

rdf - 比较 SPARQL 图

java - 如何将图库中选定的图像塑造为圆形

java - RDF 与其他数据集互连

java - 将servlet发送回Java页面或返回html页面

xml - rdf :resource, rdf:about 和 rdf:ID 的区别

rdf - 如何以编程方式确定是否注册了可以处理格式的 Jena 解析器?

sparql - 以 "t"开头的值是什么以及如何在计数时忽略它们

javascript - 在 HTML 中格式化 SPARQL 查询时的 JSON 和 JavaScript 集成

java - 将运算结果赋给常量

java - 为什么我的 android-notification 没有出现?