Ejemplo n.º 1
0
  public void evalStackEntry(
      StackEntry entry,
      LinkedList<StackEntry> stack,
      RuleExecutor executor,
      InternalWorkingMemory wm) {
    NetworkNode node = entry.getNode();
    Memory nodeMem = entry.getNodeMem();
    TupleSets<LeftTuple> trgTuples = entry.getTrgTuples();
    if (node.getType() == NodeTypeEnums.QueryElementNode) {
      // copy across the results, if any from the query node memory
      QueryElementNodeMemory qmem = (QueryElementNodeMemory) nodeMem;
      qmem.setNodeCleanWithoutNotify();
      trgTuples.addAll(qmem.getResultLeftTuples());
    }

    LeftTupleSinkNode sink = entry.getSink();
    PathMemory pmem = entry.getRmem();

    SegmentMemory[] smems = entry.getSmems();
    int smemIndex = entry.getSmemIndex();
    boolean processRian = entry.isProcessRian();

    long bit = entry.getBit();
    if (entry.isResumeFromNextNode()) {
      SegmentMemory smem = smems[smemIndex];
      if (node != smem.getTipNode()) {
        // get next node and node memory in the segment
        LeftTupleSink nextSink = sink.getNextLeftTupleSinkNode();
        if (nextSink == null) {
          node = sink;
        } else {
          // there is a nested subnetwork, take out path
          node = nextSink;
        }

        nodeMem = nodeMem.getNext();
        bit = bit << 1; // update bit to new node
      } else {
        // Reached end of segment, start on new segment.
        SegmentPropagator.propagate(smem, trgTuples, wm);
        smem = smems[++smemIndex];
        trgTuples = smem.getStagedLeftTuples().takeAll();
        node = smem.getRootNode();
        nodeMem = smem.getNodeMemories().getFirst();
        bit = 1; // update bit to start of new segment
      }
    }

    if (log.isTraceEnabled()) {
      int offset = getOffset(node);
      log.trace("{} Resume {} {}", indent(offset), node.toString(), trgTuples.toStringSizes());
    }
    innerEval(
        entry.getLiaNode(),
        pmem,
        node,
        bit,
        nodeMem,
        smems,
        smemIndex,
        trgTuples,
        wm,
        stack,
        processRian,
        executor);
  }
Ejemplo n.º 2
0
  public void eval1(
      LeftInputAdapterNode liaNode,
      PathMemory rmem,
      NetworkNode node,
      Memory nodeMem,
      SegmentMemory[] smems,
      int smemIndex,
      LeftTupleSets trgTuples,
      InternalWorkingMemory wm,
      LinkedList<StackEntry> stack,
      Set<String> visitedRules,
      boolean processRian,
      RuleExecutor executor) {
    while (true) {
      eval2(
          liaNode,
          rmem,
          node,
          nodeMem,
          smems,
          smemIndex,
          trgTuples,
          wm,
          stack,
          visitedRules,
          processRian,
          executor);

      // eval
      if (!stack.isEmpty()) {
        StackEntry entry = stack.removeLast();

        node = entry.getNode();
        nodeMem = entry.getNodeMem();
        trgTuples = entry.getTrgTuples();
        if (node.getType() == NodeTypeEnums.QueryElementNode) {
          // copy across the results, if any from the query node memory
          trgTuples.addAll(((QueryElementNodeMemory) nodeMem).getResultLeftTuples());
        }

        LeftTupleSinkNode sink = entry.getSink();
        rmem = entry.getRmem();

        smems = entry.getSmems();
        smemIndex = entry.getSmemIndex();
        visitedRules = entry.getVisitedRules();
        if (NodeTypeEnums.isBetaNode(node)) {
          // queued beta nodes do not want their ria node evaluated, otherwise there is recursion
          processRian = false;
        } else {
          processRian = true;
        }

        if (entry.isResumeFromNextNode()) {
          SegmentMemory smem = smems[smemIndex];
          if (node != smem.getTipNode()) {
            // get next node and node memory in the segment
            LeftTupleSink nextSink = sink.getNextLeftTupleSinkNode();
            if (nextSink == null) {
              node = sink;
            } else {
              // there is a nested subnetwork, take out path
              node = nextSink;
            }

            nodeMem = nodeMem.getNext();
          } else {
            // Reached end of segment, start on new segment.
            SegmentPropagator.propagate(smem, trgTuples, wm);
            smem = smems[++smemIndex];
            trgTuples = smem.getStagedLeftTuples();
            node = (LeftTupleSink) smem.getRootNode();
            nodeMem = smem.getNodeMemories().getFirst();
          }
        }

        if (log.isTraceEnabled()) {
          int offset = getOffset(node);
          log.trace("{} Resume {} {}", indent(offset), node.toString(), trgTuples.toStringSizes());
        }
      } else {
        return; // stack is empty return;
      }
    }
  }