title: 'FILTER NOT EXISTS ' operator is not working with apache jena?
body: <p>Here my sparql query code is to find Least Common Subsumer and output of query must be 'A'. I am getting blank result here. I think my query is right but seems to be Apache Jena's "filter not exists" is not working. I have also checked with other example. Is there any alternative solution of "filter not exists" or shall i need to modify my java code for that?</p>
  
  <p><strong>OWL file structure</strong></p>
  
  <pre><code> Thing:
      |
      A 
      |_P(p1,p2)
        |_M(m1,m2) 
      |
      B
  </code></pre>
  
  <p>Here A,P,M and B are the concepts. p1,p2,m1 and m2 are the instances. M is subclass of P and P is subclass of A. A and B is the subclass of Thing.</p>
  
  <p><strong>JAVA Code</strong></p>
  
  <pre><code>import org.apache.jena.iri.impl.Main;
  import com.hp.hpl.jena.query.Query;
  import com.hp.hpl.jena.query.QueryExecution;
  import com.hp.hpl.jena.query.QueryExecutionFactory;
  import com.hp.hpl.jena.query.QueryFactory;
  import com.hp.hpl.jena.query.QuerySolution;
  import com.hp.hpl.jena.query.ResultSet;
  import com.hp.hpl.jena.rdf.model.InfModel;
  import com.hp.hpl.jena.rdf.model.Model;
  import com.hp.hpl.jena.rdf.model.ModelFactory;
  import com.hp.hpl.jena.rdf.model.Resource;
  import com.hp.hpl.jena.reasoner.Reasoner;
  import com.hp.hpl.jena.reasoner.ReasonerRegistry;
  import com.hp.hpl.jena.util.FileManager;
  
  public class SPARQLReasoner {
  
      public static void main(String args[]) {
            sparqlTest();
      }
  
      public static void sparqlTest() {
          FileManager.get().addLocatorClassLoader(Main.class.getClassLoader());
          Model model;
          model = FileManager.get().loadModel("C:\\Users\\Chetan\\Desktop\\test.owl");
          Reasoner reasoner=ReasonerRegistry.getOWLReasoner();
          reasoner = reasoner.bindSchema(model);
           InfModel infmodel = ModelFactory.createInfModel(reasoner, model);
          String queryString;
          queryString = "PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; "
                  + "PREFIX owl: &lt;http://www.w3.org/2002/07/owl#&gt; "
                  + "PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt; "
                  + "PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; "
                  + "PREFIX : &lt;http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#&gt; "
  
                  +"SELECT ?lcs WHERE{ " 
                  +"?lcs ^(rdf:type/(rdfs:subClassOf)*) :p1 . "
                  +"?lcs ^(rdf:type/(rdfs:subClassOf)*) :m1 . "
                  +"?lcs rdf:type owl:Class . "
  
                  +"FILTER NOT EXISTS {?llcs ^(rdf:type/(rdfs:subClassOf)*) :p1 . "
                  +"?llcs ^(rdf:type/(rdfs:subClassOf)*) :m1 . "
                  +"?llcs rdf:type owl:Class . "
                  +"?llcs (rdfs:subClassOf)+ ?lcs . "
                  +"} "
                  +"}";
  
          Query query= QueryFactory.create(queryString);
          QueryExecution qexec= QueryExecutionFactory.create(query, infmodel);
          try{
              ResultSet results=qexec.execSelect();
              while(results.hasNext()){
                  QuerySolution soln=results.nextSolution();
                  Resource r;
                  r=soln.getResource("lcs");
                  System.out.println(r);
              }
          }finally{
              qexec.close();
          }
      }
  }
  </code></pre>
  
  <p><strong>OWL Code:</strong></p>
  
  <pre><code>&lt;rdf:RDF xmlns="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#"
       xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
       xmlns:owl="http://www.w3.org/2002/07/owl#"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
  
      &lt;owl:Ontology rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11"/&gt;
  
      &lt;owl:Class rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#A"/&gt;
  
      &lt;owl:Class rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#B"/&gt;
  
      &lt;owl:Class rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#M"&gt;
          &lt;rdfs:subClassOf rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#P"/&gt;
      &lt;/owl:Class&gt;
  
      &lt;owl:Class rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#P"&gt;
          &lt;rdfs:subClassOf rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#A"/&gt;
      &lt;/owl:Class&gt;
  
      &lt;owl:NamedIndividual rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#m1"&gt;
          &lt;rdf:type rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#M"/&gt;
      &lt;/owl:NamedIndividual&gt;
  
      &lt;owl:NamedIndividual rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#m2"&gt;
          &lt;rdf:type rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#M"/&gt;
      &lt;/owl:NamedIndividual&gt;
  
      &lt;owl:NamedIndividual rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#p1"&gt;
          &lt;rdf:type rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#P"/&gt;
      &lt;/owl:NamedIndividual&gt;
  
      &lt;owl:NamedIndividual rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#p2"&gt;
          &lt;rdf:type rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#P"/&gt;
      &lt;/owl:NamedIndividual&gt;
  
  &lt;/rdf:RDF&gt;
  </code></pre>
  
  <p>Please give your views here.</p>