简体   繁体   中英

How to get, in a given ontology, the datatype properties without a defined rdfs:range

I need to check, in a given ontology, by means of an SPARQL query, the datatype properties that does not have rdfs:range defined. For example, in the following code, the result I'm looking for would be dataproperty2 .

ont:Class1  a  owl:Class .
ont:Class2  a  owl:Class .

ont:dataProperty1  a  owl:DatatypeProperty ;
rdfs:domain  ont:Class1 ;
rdfs:label   "dataProperty1"@en ;
rdfs:range   xsd:string .

ont:dataProperty2  a  owl:DatatypeProperty ;
rdfs:domain  ont:Class2 ;
rdfs:label   "dataProperty2"@en .

I have defined this SPARQL query that retrieve the number of properties that match with this condition, but since is an aggregated function, ie, COUNT, I'm having problems to get the datatype properties, not the number, that does not have rdfs:range defined.

SELECT ?return WHERE 
{
  {
  SELECT (COUNT(?p) as ?pCount)
    WHERE
    {
      ?p rdf:type owl:DatatypeProperty .
      ?p rdfs:range ?range .
    }
  }
  {
  SELECT DISTINCT (COUNT(?p) as ?prop)
    WHERE
    {
      ?p rdf:type owl:DatatypeProperty .
    }
  }
  BIND((?prop - ?pCount) as ?return) 
}

Just select the datatype properties and then filter out the ones that don't have range properties:

select ?p where {
  ?p a owl:DatatypeProperty
  filter not exists {
    ?p rdfs:range ?range
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM