コード例 #1
0
 public int IsNewWord(String curWord) {
   for (int i = 2; i < this.nodes.size(); i++) {
     if (this.nodes.get(i).wordString.equalsIgnoreCase(curWord)) return i;
     if (WordGraphCompression.IsSameLexicalChain(this.nodes.get(i).wordString, curWord, docCount))
       return i;
   }
   return -1;
 }
コード例 #2
0
  public void NormalizedWordSal() {
    double totalWordSal = 0;
    for (int i = 0; i < this.nodes.size(); i++) {
      totalWordSal += this.nodes.get(i).salience;
    }
    for (int i = 0; i < this.nodes.size(); i++) {
      this.nodes.get(i).salience /= totalWordSal;
      WordNode tmp = WordGraphCompression.DeepCopyWordNode(this.nodes.get(i));
      this.sortedNodes.add(tmp);
    }

    Collections.sort(this.sortedNodes, new SortBySalience());
    if (this.sortedNodes.get(0).salience > this.sortedNodes.get(2).salience)
      System.out.println(">>>>>");
    else System.out.println("<<<<<<");
  }
コード例 #3
0
  public void AddCandidateToGraph(String sentence, String candidate) {
    double candiSalience = 0;
    int index = candidate.lastIndexOf("#");
    candiSalience = Double.valueOf(candidate.substring(index + 1));
    maxeventSalience = maxeventSalience > candiSalience ? maxeventSalience : candiSalience;
    candidate = candidate.substring(0, index);
    String[] candiWords = candidate.split("\\s");
    int[] candiPosition = new int[candiWords.length];
    try {
      for (int i = 0; i < candiWords.length; i++) {
        index = candiWords[i].lastIndexOf("-");
        candiPosition[i] = Integer.valueOf(candiWords[i].substring(index + 1));
        candiWords[i] = candiWords[i].substring(0, index);
      }
      if (candiWords.length > 2) this.verbs.add(candiWords[1]);
    } catch (Exception ee) {
      return;
    }

    this.sentences.add(sentence);

    String[] words = sentence.split("\\s");
    String curWord = "";

    WordNode preNode = this.nodes.get(0);
    int preNodeNo = 0;

    // add all edges to previousnodes
    ArrayList<WordNode> previousNodes = new ArrayList<WordNode>();
    ArrayList<Integer> previousNodesNo = new ArrayList<Integer>();
    previousNodes.add(this.nodes.get(0));
    previousNodesNo.add(0);

    for (int i = 0; i < words.length; i++) {
      curWord = words[i];

      if (WordGraphCompression.wordsList.containsKey(curWord) == false)
        WordGraphCompression.wordsList.put(curWord, 1);

      int curWordNo = IsNewWord(curWord);

      int distance = DistanceOfWordToCandidate(i + 1, candiPosition);

      if (curWordNo == -1) {
        WordNode newNode = new WordNode(curWord);
        newNode.mainWord =
            WordGraphCompression.GetMainWord(
                curWord, WordGraphCompression.titles.get(docCount).chains);

        newNode.salience += candiSalience * Math.exp(-1 * Math.sqrt(distance)); // /2.0
        int newNodeID = this.nodes.size();
        this.nodes.add(newNode);

        for (int kkk = 0; kkk < previousNodes.size(); kkk++) {
          Edge newEdge = new Edge(previousNodesNo.get(kkk), newNodeID);
          if (kkk != 0) newEdge.distancesInSens += 1.0 / (i + 1 - kkk);
          this.edges.add(newEdge);
        }
        previousNodes.add(newNode);
        previousNodesNo.add(newNodeID);

        Edge newEdge = new Edge(newNodeID, 1);
        this.edges.add(newEdge);

      } else {

        for (int kkk = 0; kkk < previousNodes.size(); kkk++) {
          int exist = EdgeIsExist(previousNodesNo.get(kkk), curWordNo);
          if (exist == -1) {
            if (LoopIsExist(previousNodesNo.get(kkk), curWordNo) == false) {
              Edge newEdge = new Edge(previousNodesNo.get(kkk), curWordNo);
              if (kkk != 0) newEdge.distancesInSens += 1.0 / (i + 1 - kkk);
              this.edges.add(newEdge);
            } else {
              WordNode newNode = new WordNode(curWord);
              newNode.mainWord =
                  WordGraphCompression.GetMainWord(
                      curWord, WordGraphCompression.titles.get(docCount).chains);

              for (int kkkk = 2; kkkk < this.nodes.size(); kkkk++) {
                if (this.nodes.get(kkkk).wordString.equalsIgnoreCase(curWord))
                  this.nodes.get(kkkk).salience +=
                      candiSalience * Math.exp(-1 * Math.sqrt(distance));
              }

              newNode.salience = this.nodes.get(curWordNo).salience;
              int newNodeID = this.nodes.size();
              this.nodes.add(newNode);
              curWordNo = newNodeID;

              Edge newEdge = new Edge(newNodeID, 1);
              this.edges.add(newEdge);

              for (int kkkk = 0; kkkk < previousNodes.size(); kkkk++) {
                newEdge = new Edge(previousNodesNo.get(kkkk), newNodeID);

                if (kkk != 0) newEdge.distancesInSens += 1.0 / (i + 1 - kkkk);
                this.edges.add(newEdge);
              }
            }
          } else {
            if (kkk != 0) this.edges.get(exist).distancesInSens += 1.0 / (i + 1 - kkk);
          }
        }

        preNode = this.nodes.get(curWordNo);
        previousNodes.add(preNode);
        preNode.salience += candiSalience * Math.exp(-1 * Math.sqrt(distance));
        previousNodesNo.add(curWordNo);
      }
    }
  }