1 Reply Latest reply: Aug 13, 2012 3:59 PM by 366556 RSS

    Sparql query question

    366556
      Hello,

      I have an ontology with classes X subClassOf C, C subClassOf B, B subClassOf A. And I have an inidividual ind:123 rdf:type X. This ontology is inferenced.

      How can I write a sparql query that would give me the type of ind:123 (i.e. X) and not the other types (i.e. C, B, A)?

      In other words, is there a way to right a query that would only return the "immediate" type of the subject and not all its other superclasses? I'm running Jena 2.6.4, OracleJenaAdaptor 11.2.0.3

      select *
      where { ind:123 rdf:type ?x}

      I just want to get one result

      X.

      Thanks,
      A.
        • 1. Re: Sparql query question
          Matperry-Oracle
          Hi,

          You can try:

          SELECT ?X
          WHERE
          { ind:123 rdf:type ?X .
          OPTIONAL { ind:123 rdf:type ?Y .
          ?Y rdfs:subClassOf ?X
          FILTER (!sameTerm(?Y, ?X))
          }
          FILTER (!BOUND(?Y))
          }

          This will return the most specific class for ind:123 by filtering out those superclasses that ind:123 is also an instance of.

          Hope this helps,
          - Matt