how to do reasoning in Jena via Sparql Query

前端 未结 1 352
故里飘歌
故里飘歌 2021-01-29 01:47

I\'m using Jena and Sparql to query the ontology file.

I have

  1. class Tag with two subclasses : C++ and Java.
  2. class Subject with several subclasse
相关标签:
1条回答
  • 2021-01-29 01:56

    You need to ask for things that are subclasses of Tag. Thus, something like

    ?class rdfs:subClassOf* :Tag
    

    The * means you need to match a path of 0 or more occurrences of rdfs:subClassOf, so ?class can be Tag, or a subclass of Tag, or or subclass of a subclass of Tag, etc. A complete working query would be:

    prefix :      <http://www.semanticweb.org/man/ontologies/2014/5/untitled-ontology-11#> 
    prefix owl:   <http://www.w3.org/2002/07/owl#> 
    prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> 
    
    select distinct ?subject where {
       ?subject owl:equivalentClass ?restriction .
       ?restriction owl:onProperty :hasTags .
       ?restriction ?restrictType ?class .
       ?class rdfs:subClassOf* :Tag 
    }
    
    -------------------------------------------------------------------------------------------
    | subject                                                                                 |
    ===========================================================================================
    | :Java_programming                                                                       |
    | <http://www.semanticweb.org/man/ontologies/2014/5/untitled-ontology-11#C++_programming> |
    | :System_Programming                                                                     |
    -------------------------------------------------------------------------------------------
    
    0 讨论(0)
提交回复
热议问题