how to do reasoning in Jena via Sparql Query

前端 未结 1 350
故里飘歌
故里飘歌 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 :       
    prefix owl:    
    prefix rdfs:   
    
    select distinct ?subject where {
       ?subject owl:equivalentClass ?restriction .
       ?restriction owl:onProperty :hasTags .
       ?restriction ?restrictType ?class .
       ?class rdfs:subClassOf* :Tag 
    }
    
    -------------------------------------------------------------------------------------------
    | subject                                                                                 |
    ===========================================================================================
    | :Java_programming                                                                       |
    |  |
    | :System_Programming                                                                     |
    -------------------------------------------------------------------------------------------
    

    0 讨论(0)
提交回复
热议问题