package it.unibz.krdb.obda.utils;

import it.unibz.krdb.obda.model.Atom;
import it.unibz.krdb.obda.model.CQIE;

import java.net.URI;
import java.util.Iterator;
import java.util.Vector;

import org.semanticweb.owl.model.OWLOntology;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TargetQueryValidator
{
  /** The source ontology for validating the target query */
  private OWLOntology ontology;
  
  /** List of invalid predicates */
  private Vector<String> invalidPredicates = new Vector<String>();
  
  /** Logger */
  private final Logger log = LoggerFactory.getLogger(this.getClass());
  
  public TargetQueryValidator(OWLOntology ontology) {
    this.ontology = ontology;
  }
  
  public boolean validate(CQIE targetQuery) {
    // Reset the invalid list
    invalidPredicates.clear();
    
    // Get the predicates in the target query.
    Iterator<Atom> iterAtom = targetQuery.getBody().iterator();
    while(iterAtom.hasNext()) {
      Atom atom = iterAtom.next();
      
      URI predicate = atom.getPredicate().getName();
 
      // TODO Add a predicate type for better identification.
      boolean isClass = ontology.containsClassReference(predicate);      
      boolean isObjectProp = ontology.containsObjectPropertyReference(predicate);
      boolean isDataProp = ontology.containsDataPropertyReference(predicate);
      
      // Check if the predicate contains in the ontology vocabulary as one
      // of these components (i.e., class, object property, data property).
      boolean isPredicateValid = isClass || isObjectProp || isDataProp;
      
      log.debug("\nPerdicate: " + predicate + "\n" +
          "\tClass: " + isClass + "\n" +
          "\tObject property: " + isObjectProp + "\n" +
          "\tData property: " + isDataProp);

      if(!isPredicateValid) {
        invalidPredicates.add(predicate.toString());
      }
    }
    
    boolean isValid = true;
    if(!invalidPredicates.isEmpty()) {
      isValid = false; // if the list is not empty means the string is invalid!
    }
    return isValid;
  }
  
  public Vector<String> getInvalidPredicates() {
    return invalidPredicates;
  }
}

@@ -1597,278 +1597,524 @@
     
-log.debug(%22%5CnPerdicate: %22 + predicate + %22%5Cn%22 +%0A          %22%5CtClass: %22 + isClass + %22%5Cn%22 +%0A          %22%5Ct
+String debugMsg = %22This predicate: %22 + predicate.toString();%0A      if (isPredicateValid) %7B%0A        if (isClass) %7B%0A          debugMsg += %22 is a Class.%22;%0A        %7D%0A        else if (is
 Object
- property: %22 + is
+Prop) %7B%0A          debugMsg += %22 is an 
 Object
-Prop + %22%5Cn%22 +%0A          %22%5Ct
+ property.%22;%0A        %7D%0A        else if (is
 Data
- property: %22 + is
+Prop) %7B%0A          debugMsg += %22 is a 
 Data
-Prop);%0A%0A      if(!isPredicateValid) %7B%0A        invalidPredicates.add(predicate.toString()
+ property.%22;%0A        %7D%0A        log.debug(debugMsg);%0A      %7D%0A      else %7B%0A        invalidPredicates.add(predicate.toString());%0A        log.warn(%22WARNING: %22 + debugMsg + %22 is missing in the ontology!%22
 );%0A 

Put a warn log if the target query is inconsistent with the ontology. I also improved the debug log.