Ejemplo n.º 1
0
  /**
   * Constructs a new dot chart from a specified input lattice, a translation grammar, and a parse
   * chart.
   *
   * @param input A lattice which represents an input sentence.
   * @param grammar A translation grammar.
   * @param chart A CKY+ style chart in which completed span entries are stored.
   */
  public DotChart(Lattice<Integer> input, Grammar grammar, Chart chart) {
    this.pChart = chart;
    this.pGrammar = grammar;
    this.input = input;
    this.sentLen = input.size();
    this.dotbins = new DotCell[sentLen][sentLen + 1];

    // seeding the dotChart
    seed();
  }
Ejemplo n.º 2
0
  /**
   * two kinds of symbols in the foreign side: (1) non-terminal (e.g., X or NP); (2) CN-side
   * terminal therefore, two ways to extend the dot postion.
   */
  void expandDotCell(int i, int j) {
    // if (logger.isLoggable(Level.FINEST)) logger.finest("Expanding dot cell ("+i+","+j+")");

    // (1) if the dot is just to the left of a non-terminal variable,
    //     looking for theorems or axioms in the Chart that may apply and
    //     extend the dot pos
    for (int k = i + 1; k < j; k++) { // varying middle point k
      extendDotItemsWithProvedItems(i, k, j, false);
    }

    // (2) the dot-item is looking for a CN-side terminal symbol:
    //     so we just need a CN-side terminal symbol to advance the dot in
    //     seeding case: j=i+1, therefore, it will look for l_dot_bins[i][i]
    Node<Integer> node = input.getNode(j - 1);
    for (Arc<Integer> arc : node.getOutgoingArcs()) {

      int last_word = arc.getLabel();
      // Tail and Head are backward! FIX names!
      int arc_len = arc.getTail().getNumber() - arc.getHead().getNumber();

      // int last_word=foreign_sent[j-1]; // input.getNode(j-1).getNumber(); //

      if (null != dotbins[i][j - 1]) {
        // dotitem in dot_bins[i][k]: looking for an item in the right to the dot
        for (DotNode dt : dotbins[i][j - 1].dotNodes) {
          if (null == dt.trieNode) {
            // We'll get one anyways in the else branch
            // TODO: better debugging.
            throw new NullPointerException(
                "DotChart.expand_cell(" + i + "," + j + "): " + "Null tnode for DotItem");

          } else {
            // match the terminal
            Trie child_tnode = dt.trieNode.matchOne(last_word);
            if (null != child_tnode) {
              // we do not have an ant for the terminal
              addDotItem(
                  child_tnode, i, j - 1 + arc_len, dt.antSuperNodes, null, dt.srcPath.extend(arc));
            }
          }
        } // end foreach DotItem
      }
    }
  }