Exemple #1
0
  @Override
  public ReasonerContinuationState completeNode(
      final IDecisionTree.Node<Branch<I, L, K, R>> branchNode, IABoxNode<I, L, K, R> node)
      throws EReasonerException {
    final Iterator<IDLTerm<I, L, K, R>> iter =
        ChainIterator.decorate(
            node.getTerms().subSet(DLTermOrder.DL_OBJECT_UNION).iterator(),
            node.getTerms().subSet(DLTermOrder.DL_DATA_UNION).iterator());

    final BranchActionList<I, L, K, R> branchActions = new BranchActionList<>();

    while (iter.hasNext()) {
      final IDLTerm<I, L, K, R> desc = iter.next();
      if (desc instanceof IDLUnion) {
        final IDLUnion<I, L, K, R> union = (IDLUnion<I, L, K, R>) desc;
        /* union condition: If not already one of the subterms present */
        final TermEntry<I, L, K, R> parentTerm =
            node.getABox().getTermEntryFactory().getEntry(node, desc);

        if (!CollectionUtil.containsOne(node.getTerms(), union.getTerms())) {
          for (IDLNodeTerm<I, L, K, R> subTerm : union.getTerms()) {
            branchActions.add(new TermAddBranchAction<>(parentTerm, node, subTerm));
          }
          assert !branchActions.isEmpty();
        }

        /* remove the union as a governing term */
        node.getABox()
            .getDependencyMap()
            .getGoverningTerms()
            .remove(node.getABox().getTermEntryFactory().getEntry(node, union));

        final List<BranchCreationInfo<I, L, K, R>> branchCreationInfos =
            branchActions.commit(branchNode.getData(), getNodeConsistencyChecker());

        /**
         * If we needed to branch, but all branches are inconsistent. Don't throw Exception, when we
         * did not find a branch point.
         */
        if (!branchActions.isEmpty()) {
          if (branchCreationInfos.isEmpty()) {
            /* this only happens for node merge clashes, not otherwise */
            /* XXX - do we need to change the branches consistency info? */
            return ReasonerContinuationState.INCONSISTENT;
          } else {
            if (isTracing()) {
              _logger.trace("Created %d branches", branchCreationInfos.size());
            }
            final ReasonerContinuationState contState =
                handleBranchCreation(branchCreationInfos, branchNode, node);
            if (contState != ReasonerContinuationState.CONTINUE) {
              return contState;
            }
          }
        }
      }
    }
    return ReasonerContinuationState.CONTINUE;
  }