1 Reply Latest reply on Jun 12, 2009 5:37 PM by alwu-Oracle

    SPARQL query to query an ontology using JENA

    706495
      Hello,

      I'm trying to query my OWL ontology.
      This is an example of my ontology:
          <owl:Class rdf:about="#escherichia_coli">
              <owl:equivalentClass>
                  <owl:Restriction>
                      <owl:onProperty rdf:resource="#has_genus"/>
                      <owl:someValuesFrom rdf:resource="#escherichia_genus"/>
                  </owl:Restriction>
              </owl:equivalentClass>
              <rdfs:subClassOf rdf:resource="#named_bacteria"/>
              <rdfs:subClassOf>
                  <owl:Restriction>
                      <owl:onProperty rdf:resource="#has_respiratory_mode"/>
                      <owl:someValuesFrom rdf:resource="#Aerobes"/>
                  </owl:Restriction>
              </rdfs:subClassOf>
              <rdfs:subClassOf>
                  <owl:Restriction>
                      <owl:onProperty rdf:resource="#hasGramStaining"/>
                      <owl:someValuesFrom rdf:resource="#gram_staining_negative"/>
                  </owl:Restriction>
              </rdfs:subClassOf>
              <rdfs:subClassOf>
                  <owl:Restriction>
                      <owl:onProperty rdf:resource="#has_morphology"/>
                      <owl:someValuesFrom rdf:resource="#rod"/>
                  </owl:Restriction>
              </rdfs:subClassOf>
          </owl:Class>
      I would like to retrieve all bacterium caracteristics (morphology, gram_staning, respiratory_mode).
      Whith this query, i can show the bacteria list.
      PREFIX rdfs:     <http://www.w3.org/2000/01/rdf-schema#>
      PREFIX :            <http://www.ontology.com/bacteria.owl#>
      PREFIX owl:      <http://www.w3.org/2002/07/owl#>
      
      SELECT DISTINCT *
      WHERE { 
           ?bacteria rdfs:subClassOf :named_bacteria.
           FILTER (isIRI(?bacteria) && !sameTerm(?bacteria, owl:Nothing)) 
      }
      ORDER BY (?bacteria)
      With this query, i tried to have all caracteristics, but it doesn't work (i also used the UNION clause, but it doesn't work to):
      SELECT DISTINCT ?bacteria ?genus 
      WHERE  { 
             ?bacteria rdfs:subClassOf :named_bacteria;
                       :has_genus ?genus.
                
           ?genus    rdfs:subClassOf :genus;
                
           FILTER (isIRI(?bacteria) && !sameTerm(?bacteria, owl:Nothing)) 
      
      } ORDER BY (?bacteria)
      My second question is how to use query 2 graph with JENA? I've a .java file in wich i used some JENA properties to query an OWL file (i open my owl file and my .rq file with the SPARQL query in my .java File). But i need to query also a .n3 File, is it possible to do this only in my SPARQL query?

      Please, i really need your help!
      Kind regards