Package joshua.decoder.chart_parser

Examples of joshua.decoder.chart_parser.Chart


      startTime = System.currentTimeMillis();
    }
    if (logger.isLoggable(Level.FINE))
      logger.fine("now translating\n" + segment.sentence());
   
    Chart chart; {
      //TODO: we should not use "(((" to decide whether it is a lattice input
      final boolean looksLikeLattice = segment.sentence().startsWith("(((");
      Lattice<Integer> inputLattice = null;
      Pattern sentence = null;
      if (looksLikeLattice) {
        inputLattice = Lattice.createFromString(segment.sentence(),
                  this.symbolTable);
        sentence = null; // TODO SA needs to accept lattices!
      } else {
        int[] intSentence = this.symbolTable.getIDs(segment.sentence());
        if (logger.isLoggable(Level.FINEST))
          logger.finest("Converted \"" + segment.sentence() + "\" into " + Arrays.toString(intSentence));
        inputLattice = Lattice.createLattice(intSentence);
        sentence = new Pattern(this.symbolTable, intSentence);
      }
      if (logger.isLoggable(Level.FINEST))
        logger.finest("Translating input lattice:\n" + inputLattice.toString());

      Grammar[] grammars = new Grammar[grammarFactories.size()];
      int i = 0;
      for (GrammarFactory factory : this.grammarFactories) {
        grammars[i] = factory.getGrammarForSentence(sentence);
       
        // For batch grammar, we do not want to sort it every time
        if (! grammars[i].isSorted()) {
          System.out.println("!!!!!!!!!!!! called again");
          // TODO Check to see if this is ever called here. It probably is not
          grammars[i].sortGrammar(this.featureFunctions);
        }
       
        i++;
      }
     
     
      /* Seeding: the chart only sees the grammars, not the factories */
      chart = new Chart(
        inputLattice,
        this.featureFunctions,
        this.stateComputers,
        this.symbolTable,
        Integer.parseInt(segment.id()),
        grammars,
        this.hasLanguageModel,
        JoshuaConfiguration.goal_symbol,
        segment.constraints());
     
      if (logger.isLoggable(Level.FINER))
        logger.finer("after seed, time: "
          + ((double)(System.currentTimeMillis() - startTime) / 1000.0)
          + " seconds");
    }
   
   
   
    /* Parsing */
    HyperGraph hypergraph = chart.expand();
   
    if (JoshuaConfiguration.visualize_hypergraph) {
      HyperGraphViewer.visualizeHypergraphInFrame(hypergraph, symbolTable);
    }
   
View Full Code Here


 
 
  /**decode a sentence, and return a hypergraph*/
  public HyperGraph getHyperGraph(String sentence)
  {
    Chart chart;
   
    int[] intSentence = this.symbolTable.getIDs(sentence);
    Lattice<Integer> inputLattice = Lattice.createLattice(intSentence);
   
    Grammar[] grammars = new Grammar[grammarFactories.size()];
    int i = 0;
    for (GrammarFactory factory : this.grammarFactories) {
      grammars[i] = factory.getGrammarForSentence(
          new Pattern(this.symbolTable, intSentence));
     
      // For batch grammar, we do not want to sort it every time
      if (! grammars[i].isSorted()) {
        grammars[i].sortGrammar(this.featureFunctions);
      }
     
      i++;
    }
   
    chart = new Chart(
        inputLattice,
        this.featureFunctions,
        this.stateComputers,
        this.symbolTable,
        0,
        grammars,
        this.hasLanguageModel,
        JoshuaConfiguration.goal_symbol,
        null);
   
    return chart.expand();
  }
View Full Code Here

      grammars[i] = grammarFactories[i].getGrammarForSentence(null);//??????????????????????????????????????????????????????????????????????
//      grammars[i].sortGrammar(models);//TODO: for batch grammar, we do not want to sort it every time
    }
   
    //==========================seeding: the chart only sees the grammars, not the grammarFactories
    Chart chart = new Chart(
      inputLattice,
      models,
      null,
      this.symbolTable,
      sentenceID,
      grammars,
      this.haveLMModel,
      JoshuaConfiguration.goal_symbol,
      null);
    if (logger.isLoggable(Level.FINER))
      logger.finer("after seed, time: "
        + (System.currentTimeMillis() - start) / 1000);
   
    //=========================parsing
    HyperGraph p_hyper_graph = chart.expand();
    if (logger.isLoggable(Level.FINER))
      logger.finer("after expand, time: "  + (System.currentTimeMillis() - start) / 1000);   
   
    postProcessHypergraph(p_hyper_graph, sentenceID);
  }
View Full Code Here

TOP

Related Classes of joshua.decoder.chart_parser.Chart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.