简体   繁体   中英

How to add classes to a specific class in an ontology with sparql?

We have a question about sparql, because we're trying to link classes from dbpedia to our ontology in Protégé. Our protégé is about pets. We're trying with the query below to get all the dog breeds from dbpedia and implement them as a subclass to our class 'Dog' in Protégé.

What happens with this query is that all the dog breeds become normal classes our ontology, but we want it to be subclasses of the class 'Dog'.

Thanks a lot!

    PREFIX dbo: <http://dbpedia.org/ontology/>
    PREFIX umbelrc: <http://umbel.org/umbel/rc/>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX dct: <http://purl.org/dc/terms/>
    PREFIX ex: <http://data.kingcounty.cov/resource/yaai-7rfk/>
    PREFIX dbc: <http://dbpedia.org/resource/Category:>


    CONSTRUCT {
      ?x a owl:Class .
      ?x owl:equivalentClass [
        rdf:type owl:Restriction ;
        owl:onProperty ex:animal_type ;
        owl:hasValue ?xls ;
      ] .
    } WHERE {
      SELECT ?x ?xls WHERE {
      ?x a dbc:Dog_breeds .
      ?x rdfs:label ?xl .
      FILTER(lang(?xl) = 'en')
        BIND(str(?xl) as ?xls)
      }
    } 

Resources are connected to a DBpedia category by the property dct:subject and not rdf:type (aka a in Turtle). that means, change the triple pattern from

?x a dbc:Dog_breeds .

to

?x dct:subject dbc:Dog_breeds .

should work (modulo other issues that might arise afterwards indeed).

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