コード例 #1
0
  /**
   * The basic method for splitting off a clause of a tree. This modifies the tree in place. This
   * method addtionally follows ref edges.
   *
   * @param tree The tree to split a clause from.
   * @param toKeep The edge representing the clause to keep.
   */
  @SuppressWarnings("unchecked")
  private void simpleClause(SemanticGraph tree, SemanticGraphEdge toKeep) {
    splitToChildOfEdge(tree, toKeep);

    // Follow 'ref' edges
    Map<IndexedWord, IndexedWord> refReplaceMap = new HashMap<>();
    // (find replacements)
    for (IndexedWord vertex : tree.vertexSet()) {
      for (SemanticGraphEdge edge : extraEdgesByDependent.get(vertex)) {
        if ("ref".equals(edge.getRelation().toString())
            && // it's a ref edge...
            !tree.containsVertex(
                edge.getGovernor())) { // ...that doesn't already exist in the tree.
          refReplaceMap.put(vertex, edge.getGovernor());
        }
      }
    }
    // (do replacements)
    for (Map.Entry<IndexedWord, IndexedWord> entry : refReplaceMap.entrySet()) {
      Iterator<SemanticGraphEdge> iter = tree.incomingEdgeIterator(entry.getKey());
      if (!iter.hasNext()) {
        continue;
      }
      SemanticGraphEdge incomingEdge = iter.next();
      IndexedWord governor = incomingEdge.getGovernor();
      tree.removeVertex(entry.getKey());
      addSubtree(
          tree,
          governor,
          incomingEdge.getRelation().toString(),
          this.tree,
          entry.getValue(),
          this.tree.incomingEdgeList(tree.getFirstRoot()));
    }
  }
コード例 #2
0
  private Counter<String> uniformRandom() {
    Counter<String> uniformRandom =
        new ClassicCounter<>(MapFactory.<String, MutableDouble>linkedHashMapFactory());
    for (Map<SentenceKey, EnsembleStatistics> impl : this.impl) {
      for (Map.Entry<SentenceKey, EnsembleStatistics> entry : impl.entrySet()) {
        uniformRandom.setCount(entry.getKey().sentenceHash, 1.0);
      }
    }

    return uniformRandom;
  }
コード例 #3
0
  private Counter<String> highKLFromMean() {
    // Get confidences
    Counter<String> kl =
        new ClassicCounter<>(MapFactory.<String, MutableDouble>linkedHashMapFactory());
    for (Map<SentenceKey, EnsembleStatistics> impl : this.impl) {
      for (Map.Entry<SentenceKey, EnsembleStatistics> entry : impl.entrySet()) {
        kl.setCount(entry.getKey().sentenceHash, entry.getValue().averageKLFromMean());
      }
    }

    return kl;
  }
コード例 #4
0
 private Counter<String> lowAverageConfidence() {
   // Get confidences
   Counter<String> lowConfidence =
       new ClassicCounter<>(MapFactory.<String, MutableDouble>linkedHashMapFactory());
   for (Map<SentenceKey, EnsembleStatistics> impl : this.impl) {
     for (Map.Entry<SentenceKey, EnsembleStatistics> entry : impl.entrySet()) {
       SentenceStatistics average = entry.getValue().mean();
       for (double confidence : average.confidence) {
         lowConfidence.setCount(entry.getKey().sentenceHash, 1 - confidence);
       }
     }
   }
   return lowConfidence;
 }