通过SPARQL查询获取RDF图的结构

时间:2017-10-04 09:08:27

标签: sparql rdf rdfs

如何才能获得表示图形结构的三元组 - 类和属性层次结构(即没有个体,属性值)?

1 个答案:

答案 0 :(得分:0)

似乎我需要rdf:type,owl:class等三元组。这就是我的变体:

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

select ?s ?p ?o 
where
{
    {
        graph <http://graph.org/gr>
        {       
            ?s rdf:type ?o.
            ?s ?p ?o.
        }
        FILTER
            (?o IN (owl:Class, owl:DatatypeProperty, owl:AnnotationProperty, owl:ObjectProperty, owl:DataRange, owl:Ontology,
            owl:DataRange,owl:DeprecatedClass,owl:DeprecatedProperty,owl:OntologyProperty,rdfs:Class,owl:Restriction,owl:InverseFunctionalProperty,
            owl:FunctionalProperty,owl:AllDisjointClasses,rdf:Property, rdfs:Datatype )
            )
}
UNION
{
        graph <http://graph.org/gr>
        {
            ?s ?p ?o.
        }
        FILTER
            (?p IN (rdfs:subClassOf,rdfs:subPropertyOf,rdfs:domain,rdfs:range,rdfs:label,rdfs:comment,rdfs:member,
            rdf:first,rdf:rest,owl:allValuesFrom,owl:someValuesFrom,owl:AnnotationProperty,owl:equivalentClass,
            owl:equivalentProperty,owl:hasValue,owl:OntologyProperty,owl:SymmetricProperty,owl:TransitiveProperty,
            owl:versionInfo,owl:priorVersion,owl:oneOf,owl:maxCardinality,owl:minCardinality,owl:inverseOf,
            owl:incompatibleWith,owl:intersectionOf,owl:imports,owl:backwardCompatibleWith,owl:AllDifferent,
            owl:differentFrom,owl:disjointWith,owl:distinctMembers,owl:complementOf,owl:cardinality,owl:unionOf,owl:onProperty))
        }
}