public Instance getInstance(Identifier id, Concept concept) {
    reasoner.deRegisterOntology((IRI) (state.getIdentifier()));
    try {
      reasoner.registerOntology(state);
    } catch (InconsistencyException e) {
      logger.warn("Ontology registration failed.", e);
    }
    Set<Instance> instances = reasoner.getInstances((IRI) state.getIdentifier(), concept);
    Instance instance = null;
    for (Instance i : instances) if (i.getIdentifier().equals(id)) instance = i;
    for (Entry<Molecule, Axiom> e : axioms.entrySet()) {
      if (e.getKey() instanceof AttributeValueMolecule) {
        AttributeValueMolecule avm = (AttributeValueMolecule) e.getKey();
        Axiom axiom = e.getValue();

        if (avm.getLeftParameter().equals(instance.getIdentifier())) {
          try {
            instance.addAttributeValue((IRI) avm.getAttribute(), (Value) avm.getRightParameter());
          } catch (Exception e2) {
            logger.warn("Failed to pseudo-reason.", e2);
          }
        }
      }
    }

    return instance;
  }
 public boolean holds(Condition condition) {
   logger.debug(
       "Executing ground query "
           + condition
           + " over "
           + state.getIdentifier()
           + " with "
           + state.listInstances().size()
           + " instances and "
           + state.listAxioms().size()
           + " axioms.");
   try {
     reasoner.deRegisterOntology((IRI) (state.getIdentifier()));
   } catch (Throwable t) {
     // silent
     // TODO log warn
   }
   try {
     reasoner.registerOntology(state);
   } catch (InconsistencyException e) {
     logger.warn("Ontology registration failed.", e);
   }
   return reasoner.executeGroundQuery(
       (IRI) state.getIdentifier(), condition.getRestrictedLogicalExpression());
 }
  public Set<Map<Variable, Term>> retrieveBinding(Condition condition) {
    logger.debug(
        "Executing query "
            + condition
            + " over "
            + state.getIdentifier()
            + " with "
            + state.listInstances().size()
            + " instances and "
            + state.listAxioms().size()
            + " axioms.");
    try {
      reasoner.deRegisterOntology((IRI) (state.getIdentifier()));
    } catch (Exception e) {
      // allow for kaon
    }

    try {
      reasoner.registerOntology(state);
    } catch (InconsistencyException e) {
      logger.warn("Ontology registration failed.", e);
    }
    Set<Map<Variable, Term>> instances =
        reasoner.executeQuery(
            (IRI) state.getIdentifier(), condition.getRestrictedLogicalExpression());
    return instances;
  }
 public boolean isOut(Instance instance) {
   if (instance.getIdentifier() instanceof UnnumberedAnonymousID) return false;
   for (Out mode : signature.listOutModes()) {
     if (reasoner.isMemberOf((IRI) state.getIdentifier(), instance, mode.getConcept()))
       return true;
   }
   return false;
 }
  /* (non-Javadoc)
   * @see ie.deri.wsmx.asm.State#add(org.omwg.ontology.Instance)
   */
  public Grounding add(Instance instance)
      throws SynchronisationException, InvalidModelException, UpdateIllegalException {
    // FIXME check if instance is of correct mode and throw UpdateIllegal if not

    state.addInstance(instance);
    try {
      reasoner.deRegisterOntology((IRI) (state.getIdentifier()));
    } catch (Throwable t) {
      // silent
      // TODO log warn
    }
    try {
      reasoner.registerOntology(state);
    } catch (InconsistencyException e1) {
      logger.warn("Ontology registration failed:" + e1.getMessage(), e1);
    }
    for (In mode : signature.listInModes()) {
      if (reasoner.isMemberOf((IRI) state.getIdentifier(), instance, mode.getConcept()))
        try {
          return mode.getGrounding().iterator().next();
        } catch (NotGroundedException e) {
          // FIXME
          return null;
        }
    }
    for (Out mode : signature.listOutModes()) {
      if (reasoner.isMemberOf((IRI) state.getIdentifier(), instance, mode.getConcept()))
        try {
          return mode.getGrounding().iterator().next();
        } catch (NotGroundedException e) {
          return null;
        }
    }

    throw new UpdateIllegalException();
  }