private void tryAdd(Statement stmt) {
   boolean sendToPellet = false;
   if (pipeOpen
       && reasonerConfiguration.getReasonOnAllDatatypePropertyStatements()
       && stmt.getObject().isLiteral()) {
     sendToPellet = true;
   } else if (pipeOpen && hasCardinalityPredicate(stmt)) { // see comment on this method
     sendToPellet = true;
   } else if ((stmt.getObject().isResource())
       && !((stmt.getPredicate().getURI().indexOf(VitroVocabulary.vitroURI) == 0))) {
     if (pipeOpen) {
       sendToPellet = false;
       boolean denied = false;
       ObjectPropertyStatementPattern stPat =
           ObjectPropertyStatementPatternFactory.getPattern(
               stmt.getSubject(), stmt.getPredicate(), (Resource) stmt.getObject());
       if (inferenceDrivingPatternDenySet != null) {
         for (Iterator<ObjectPropertyStatementPattern> i =
                 inferenceDrivingPatternDenySet.iterator();
             i.hasNext(); ) {
           ObjectPropertyStatementPattern pat = i.next();
           if (pat.matches(stPat)) {
             denied = true;
             break;
           }
         }
       }
       if (!denied) {
         if (inferenceDrivingPatternAllowSet == null) {
           sendToPellet = true;
         } else {
           // TODO: O(1) implementation of this
           List<ObjectPropertyStatementPattern> patList =
               this.inferenceDrivingPatternMap.get(stmt.getPredicate());
           if (patList != null) {
             for (Iterator<ObjectPropertyStatementPattern> i = patList.iterator(); i.hasNext(); ) {
               ObjectPropertyStatementPattern pat = i.next();
               if (pat.matches(stPat)) {
                 sendToPellet = true;
                 break;
               }
             }
           }
         }
       }
     }
   }
   if (sendToPellet) {
     // long startTime = System.currentTimeMillis();
     String valueStr =
         (stmt.getObject().isResource())
             ? ((Resource) stmt.getObject()).getLocalName()
             : ((Literal) stmt.getObject()).getLexicalForm();
     if (log.isDebugEnabled()) {
       log.debug("Adding to Pellet: " + renderStatement(stmt));
     }
     additionModel.enterCriticalSection(Lock.WRITE);
     try {
       additionModel.add(stmt);
     } finally {
       additionModel.leaveCriticalSection();
     }
   } else {
     if (log.isDebugEnabled()) {
       log.debug("Not adding to Pellet: " + renderStatement(stmt));
     }
   }
 }
 private void tryRemove(Statement stmt) {
   boolean removeFromPellet = false;
   if (pipeOpen
       && reasonerConfiguration.getReasonOnAllDatatypePropertyStatements()
       && stmt.getObject().isLiteral()) {
     removeFromPellet = true;
   } else if (pipeOpen && hasCardinalityPredicate(stmt)) { // see comment on this method
     removeFromPellet = true;
   } else if (stmt.getObject().isResource()) {
     if (pipeOpen) {
       if (reasonerConfiguration.getQueryForAllObjectProperties()
           && stmt.getPredicate().equals(RDF.type)
           && stmt.getObject().equals(OWL.ObjectProperty)) {
         deletedObjectProperties.enterCriticalSection(Lock.WRITE);
         try {
           deletedObjectProperties.add(stmt);
         } finally {
           deletedObjectProperties.leaveCriticalSection();
         }
       }
       if (reasonerConfiguration.getQueryForAllDatatypeProperties()
           && stmt.getPredicate().equals(RDF.type)
           && stmt.getObject().equals(OWL.DatatypeProperty)) {
         deletedDataProperties.enterCriticalSection(Lock.WRITE);
         try {
           deletedDataProperties.add(stmt);
         } finally {
           deletedDataProperties.leaveCriticalSection();
         }
       }
       removeFromPellet = false;
       boolean denied = false;
       ObjectPropertyStatementPattern stPat =
           ObjectPropertyStatementPatternFactory.getPattern(
               stmt.getSubject(), stmt.getPredicate(), (Resource) stmt.getObject());
       if (inferenceDrivingPatternDenySet != null) {
         for (Iterator<ObjectPropertyStatementPattern> i =
                 inferenceDrivingPatternDenySet.iterator();
             i.hasNext(); ) {
           ObjectPropertyStatementPattern pat = i.next();
           if (pat.matches(stPat)) {
             denied = true;
             break;
           }
         }
       }
       if (!denied) {
         if (inferenceDrivingPatternAllowSet == null) {
           removeFromPellet = true;
         } else {
           // TODO: O(1) implementation of this
           List<ObjectPropertyStatementPattern> patList =
               this.inferenceDrivingPatternMap.get(stmt.getPredicate());
           if (patList != null) {
             for (Iterator<ObjectPropertyStatementPattern> i = patList.iterator(); i.hasNext(); ) {
               ObjectPropertyStatementPattern pat = i.next();
               if (pat.matches(stPat)) {
                 removeFromPellet = true;
                 break;
               }
             }
           }
         }
       }
     }
   }
   if (removeFromPellet) {
     String valueStr =
         (stmt.getObject().isResource())
             ? ((Resource) stmt.getObject()).getLocalName()
             : ((Literal) stmt.getObject()).getLexicalForm();
     log.info(
         "Removing from Pellet: "
             + stmt.getSubject().getLocalName()
             + " "
             + stmt.getPredicate().getLocalName()
             + " "
             + valueStr);
     removalModel.enterCriticalSection(Lock.WRITE);
     try {
       removalModel.add(stmt);
     } finally {
       removalModel.leaveCriticalSection();
     }
   }
 }
  public PelletListener(
      OntModel fullModel,
      OntModel model,
      Model inferenceModel,
      ReasonerConfiguration reasonerConfiguration,
      boolean foreground,
      boolean skipReasoningUponInitialization) {
    this.pelletModel = ModelFactory.createOntologyModel(reasonerConfiguration.getOntModelSpec());
    this.fullModel = fullModel;
    this.mainModel = model;
    this.inferenceModel = inferenceModel;
    if (this.inferenceModel == null) {
      log.trace("Inference model is null");
    }
    this.reasonerConfiguration = reasonerConfiguration;
    this.inferenceDrivingPatternAllowSet =
        reasonerConfiguration.getInferenceDrivingPatternAllowSet();
    this.inferenceDrivingPatternDenySet = reasonerConfiguration.getInferenceDrivingPatternDenySet();
    this.inferenceReceivingPatternAllowSet =
        reasonerConfiguration.getInferenceReceivingPatternAllowSet();

    if (this.inferenceDrivingPatternAllowSet != null) {
      this.inferenceDrivingPatternMap =
          new HashMap<Property, List<ObjectPropertyStatementPattern>>();
      for (Iterator<ObjectPropertyStatementPattern> i = inferenceDrivingPatternAllowSet.iterator();
          i.hasNext(); ) {
        ObjectPropertyStatementPattern pat = i.next();
        Property p = pat.getPredicate();
        List<ObjectPropertyStatementPattern> patList = inferenceDrivingPatternMap.get(p);
        if (patList == null) {
          patList = new LinkedList<ObjectPropertyStatementPattern>();
          patList.add(pat);
          inferenceDrivingPatternMap.put(p, patList);
        } else {
          patList.add(pat);
        }
      }
    }
    this.pipeOpen = true;
    this.additionModel = ModelFactory.createDefaultModel();
    this.removalModel = ModelFactory.createDefaultModel();
    this.deletedObjectProperties = ModelFactory.createDefaultModel();
    this.deletedDataProperties = ModelFactory.createDefaultModel();
    this.mainModel.enterCriticalSection(Lock.READ);
    try {
      for (ObjectPropertyStatementPattern pat : this.inferenceDrivingPatternAllowSet) {
        addedStatements(
            mainModel.listStatements((Resource) null, pat.getPredicate(), (RDFNode) null));
      }
      if (!skipReasoningUponInitialization) {
        this.foreground = foreground;
        notifyEvent(null, new EditEvent(null, false));
      } else if (inferenceModel.size() == 0) {
        foreground = true;
        notifyEvent(null, new EditEvent(null, false));
        this.foreground = foreground;
      }
    } finally {
      this.mainModel.leaveCriticalSection();
    }

    this.fullModel.getBaseModel().register(this);
    this.mainModel.getBaseModel().register(this);
  }