コード例 #1
0
ファイル: MDAG.java プロジェクト: liuzl/HanLP
  /**
   * 从给点节点开始克隆一条路径<br>
   * Clones a _transition path from a given node.
   *
   * @param pivotConfluenceNode the MDAGNode that the cloning operation is to be based from
   * @param transitionStringToPivotNode a String which corresponds with a _transition path from
   *     souceNode to {@code pivotConfluenceNode}
   * @param str a String which corresponds to the _transition path from {@code pivotConfluenceNode}
   *     that is to be cloned
   */
  private void cloneTransitionPath(
      MDAGNode pivotConfluenceNode, String transitionStringToPivotNode, String str) {
    MDAGNode lastTargetNode =
        pivotConfluenceNode.transition(
            str); // Will store the last node which was used as the base of a cloning operation
    MDAGNode lastClonedNode = null; // Will store the last cloned node
    char lastTransitionLabelChar =
        '\0'; // Will store the char which labels the _transition to lastTargetNode from its parent
              // node in the prefixString's _transition path

    // Loop backwards through the indices of str, using each as a boundary to create substrings of
    // str of decreasing length
    // which will be used to _transition to, and duplicate the nodes in the _transition path of str
    // from pivotConfluenceNode.
    for (int i = str.length(); i >= 0; i--) {
      String currentTransitionString = (i > 0 ? str.substring(0, i) : null);
      MDAGNode currentTargetNode =
          (i > 0 ? pivotConfluenceNode.transition(currentTransitionString) : pivotConfluenceNode);
      MDAGNode clonedNode;

      if (i == 0) // if we have reached pivotConfluenceNode
      {
        // Clone pivotConfluenceNode in a way that reassigns the _transition of its parent node (in
        // transitionStringToConfluenceNode's path) to the clone.
        String transitionStringToPivotNodeParent =
            transitionStringToPivotNode.substring(0, transitionStringToPivotNode.length() - 1);
        char parentTransitionLabelChar =
            transitionStringToPivotNode.charAt(transitionStringToPivotNode.length() - 1);
        clonedNode =
            pivotConfluenceNode.clone(
                sourceNode.transition(transitionStringToPivotNodeParent),
                parentTransitionLabelChar);
        /////
      } else clonedNode = currentTargetNode.clone(); // simply clone curentTargetNode

      transitionCount += clonedNode.getOutgoingTransitionCount();

      // If this isn't the first node we've cloned, reassign clonedNode's _transition labeled
      // with the lastTransitionChar (which points to the last targetNode) to the last clone.
      if (lastClonedNode != null) {
        clonedNode.reassignOutgoingTransition(
            lastTransitionLabelChar, lastTargetNode, lastClonedNode);
        lastTargetNode = currentTargetNode;
      }

      // Store clonedNode and the char which labels the _transition between the node it was cloned
      // from (currentTargetNode) and THAT node's parent.
      // These will be used to establish an equivalent _transition to clonedNode from the next clone
      // to be created (it's clone parent).
      lastClonedNode = clonedNode;
      lastTransitionLabelChar = (i > 0 ? str.charAt(i - 1) : '\0');
      /////
    }
    /////
  }
コード例 #2
0
ファイル: MDAG.java プロジェクト: liuzl/HanLP
  private void splitTransitionPath(MDAGNode originNode, String storedStringSubstr) {
    HashMap<String, Object> firstConfluenceNodeDataHashMap =
        getTransitionPathFirstConfluenceNodeData(originNode, storedStringSubstr);
    Integer toFirstConfluenceNodeTransitionCharIndex =
        (Integer) firstConfluenceNodeDataHashMap.get("toConfluenceNodeTransitionCharIndex");
    MDAGNode firstConfluenceNode = (MDAGNode) firstConfluenceNodeDataHashMap.get("confluenceNode");

    if (firstConfluenceNode != null) {
      MDAGNode firstConfluenceNodeParent =
          originNode.transition(
              storedStringSubstr.substring(0, toFirstConfluenceNodeTransitionCharIndex));

      MDAGNode firstConfluenceNodeClone =
          firstConfluenceNode.clone(
              firstConfluenceNodeParent,
              storedStringSubstr.charAt(toFirstConfluenceNodeTransitionCharIndex));

      transitionCount += firstConfluenceNodeClone.getOutgoingTransitionCount();

      String unprocessedSubString =
          storedStringSubstr.substring(toFirstConfluenceNodeTransitionCharIndex + 1);
      splitTransitionPath(firstConfluenceNodeClone, unprocessedSubString);
    }
  }