查询所有" AnnotationAssertions"对于一个班级/个人

时间:2014-10-30 15:07:57

标签: 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..

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

SPARQL-DL API提供了通过

查询annotationproperties的可能性
Annotation(a, b, c)

查询AnnotationAssertions的任何指针都非常有用。

1 个答案:

答案 0 :(得分:2)

您在问题中提到了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:properties)。例如,

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 ) )
}