Package joshua.decoder.ff.tm

Examples of joshua.decoder.ff.tm.Rule


        computeCost(parentNode, edge, modelCost, models);
      }
     
      //### get hyp string recursively
      StringBuffer res = new StringBuffer();
      Rule rl = edge.getRule();
     
      if (null == rl) { // hyperedges under "goal item" does not have rule
        if (useTreeFormat) {
          //res.append("(ROOT ");
          res.append('(');
          res.append(rootID);
          if (includeAlign) {
            // append "{i-j}"
            res.append('{');
            res.append(parentNode.i);
            res.append('-');
            res.append(parentNode.j);
            res.append('}');
          }
          res.append(' ');
        }
        for (int id = 0; id < edge.getAntNodes().size(); id++) {
          res.append( getChildDerivationState(kbestExtator, edge, id).getHypothesis(symbolTbl,kbestExtator, useTreeFormat, modelCost, models, numNodesAndEdges) );
          if (id < edge.getAntNodes().size()-1) res.append(' ');
        }
        if (useTreeFormat)
          res.append(')');
      } else {
        if (useTreeFormat) {
          res.append('(');
          res.append(rl.getLHS());
          if (includeAlign) {
            // append "{i-j}"
            res.append('{');
            res.append(parentNode.i);
            res.append('-');
            res.append(parentNode.j);
            res.append('}');
          }
          res.append(' ');
        }
        if (!isMonolingual) { // bilingual
          int[] english = rl.getEnglish();
          for (int c = 0; c < english.length; c++) {
            if (symbolTbl.isNonterminal(english[c])) {
              int id = symbolTbl.getTargetNonterminalIndex(english[c]);
              res.append( getChildDerivationState(kbestExtator, edge, id).getHypothesis(symbolTbl, kbestExtator, useTreeFormat, modelCost, models, numNodesAndEdges));
            } else {
              res.append(english[c]);
            }
            if (c < english.length-1) res.append(' ');
          }
        } else { // monolingual
          int[] french = rl.getFrench();
          int nonTerminalID = 0;//the position of the non-terminal in the rule
          for (int c = 0; c < french.length; c++) {
            if (symbolTbl.isNonterminal(french[c])) {
              res.append( getChildDerivationState(kbestExtator, edge, nonTerminalID).getHypothesis(symbolTbl,kbestExtator, useTreeFormat, modelCost, models, numNodesAndEdges));
              nonTerminalID++;
View Full Code Here


 
  private void writeHyperedge(HGNode node, HyperEdge edge)
  throws IOException {
    //get rule id
    int ruleID = NULL_RULE_ID;
    final Rule edgeRule = edge.getRule();
    if (null != edgeRule) {
      ruleID = edgeRule.getRuleID();
      if  (! isOutOfVocabularyRule(edgeRule)) {
        this.associatedGrammar.put(ruleID, edgeRule); //remember used regular rule
      }
    }
   
    StringBuffer s = new StringBuffer();
    //line: bestLogP, numNodes, item_ids, rule id, OOV-Non-Terminal (optional), OOV (optional),
    s.append(String.format("%.4f ", edge.bestDerivationLogP));
    //s.append(" ").append(cur_d.bestDerivationLogP).append(" ");//this 1.2 faster than the previous statement
   
    //s.append(String.format("%.4f ", cur_d.get_transition_logP(false)));
    //s.append(cur_d.get_transition_logP(false)).append(" ");//this 1.2 faster than the previous statement, but cost 1.4 larger disk space
   
    if (null == edge.getAntNodes()) {
      s.append(0);
    } else {
      final int qtyItems = edge.getAntNodes().size();
      s.append(qtyItems);
      for (int i = 0; i < qtyItems; i++) {
        s.append(' ')
          .append(this.itemToID.get(
            edge.getAntNodes().get(i) ));
      }
    }
    s.append(' ')
      .append(ruleID);
    //if (ruleID == MemoryBasedBatchGrammar.OOV_RULE_ID) {//pGrammar.getOOVRuleID()) {
    if (edgeRule != null) {
                //System.out.println("lhs id: " + deduction_rule.getLHS());
      //System.out.println("rule words: " + deduction_rule.getEnglish());
      s.append(' ')
        .append(this.symbolTable.getWord(edgeRule.getLHS()))
        .append(' ')
        .append(this.symbolTable.getWords(edgeRule.getEnglish()));
    }
    s.append('\n');
   
    // save model logPs as a seprate line; optional
    if (this.storeModelLogP) {
View Full Code Here

        antecedentItems.add(item);
      }
    }
   
    //rule_id
    Rule rule = null;
    final int ruleID = Integer.parseInt(fds[2+qtyAntecedents]);
    if (ruleID != NULL_RULE_ID) {
      if (ruleID != MemoryBasedBatchGrammar.OOV_RULE_ID) {//pGrammar.getOOVRuleID()) {
        rule = this.associatedGrammar.get(ruleID);
        if (null == rule) {
          throw new RuntimeException("rule is null but id is " + ruleID);
        }
      } else {
        rule = pGrammar.constructOOVRule(1this.symbolTable.addTerminal(fds[4+qtyAntecedents]), this.symbolTable.addTerminal(fds[4+qtyAntecedents]), false);
       
        /**This is a hack. as the pGrammar does not set defaultLHS properly*/
        int lhs = this.symbolTable.addNonterminal(fds[3+qtyAntecedents]);
        rule.setLHS(lhs);
      }
    } else {
      // Do nothing: goal item has null rule
    }
   
View Full Code Here

              sourcePattern,
              sourcePatternCount,
              translation,
              counts, p_e_given_f_denominator);

        Rule rule = new BilingualRule(
            SymbolTable.X,
            sourcePattern.getWordIDs(),
            translation.getWordIDs(),
            featureScores,
            translation.arity(),
View Full Code Here

                }
                this.spansWithHardRuleConstraint.add(new Span(cSpan.start(), cSpan.end()));               
              }
             
              int arity = 0; // only allow flat rule (i.e. arity=0)
              Rule rule = this.grammarForConstructManualRule.constructManualRule(
                  symbolTable.addNonterminal(cRule.lhs()),
                  symbolTable.addTerminals(cRule.foreignRhs()),
                  symbolTable.addTerminals(cRule.nativeRhs()),
                  featureScores,
                  arity);
             
              //add to the chart
              chart.addAxiom(cSpan.start(), cSpan.end(), rule, new SourcePath());
              if (logger.isLoggable(Level.INFO))
                logger.info("Adding RULE constraint for span " + cSpan.start() + ", " + cSpan.end() + "; isHard=" + cSpan.isHard() +rule.getLHS());
              break;
             
            default:
              shouldAdd = true;
            }
View Full Code Here

        // create a rule, but do not add into the grammar trie
        // TODO: which grammar should we use to create an OOV rule?
//        this is the regular grammar
        int sourceWord = arc.getLabel();
        int targetWord = symbolTable.addTerminal( symbolTable.getWord(sourceWord)+"_OOV");
        Rule rule = this.grammars[1].constructOOVRule(
          this.featureFunctions.size(), sourceWord, targetWord, hasLM);
     
        if (manualConstraintsHandler.containHardRuleConstraint(node.getNumber(), arc.getTail().getNumber())) {
          //do not add the oov axiom
          if (logger.isLoggable(Level.FINE))
View Full Code Here

    if (null == rules || rules.size() <= 0) {
      return;
    }
   
    //===== seed the heap with best node
    Rule currentRule = rules.get(0);
    List<HGNode> currentAntNodes = new ArrayList<HGNode>();
    for (SuperNode si : superNodes) {
      // TODO: si.nodes must be sorted
      currentAntNodes.add(si.nodes.get(0));
    }
    ComputeNodeResult result =  new ComputeNodeResult(featureFunctions, currentRule, currentAntNodes, i, j, srcPath, stateComputers, chart.segmentID);
   
    int[] ranks = new int[1+superNodes.size()]; // rule, ant items
    for (int d = 0; d < ranks.length; d++) {
      ranks[d] = 1;
    }
   
    CubePruneState bestState =  new CubePruneState(result, ranks, currentRule, currentAntNodes);
    combinationHeap.add(bestState);
    cubeStateTbl.put(bestState.getSignature(),1);
    // cube_state_tbl.put(best_state,1);
   
    //====== extend the heap
    Rule   oldRule = null;
    HGNode oldItem = null;
    int    tem_c   = 0;
    while (combinationHeap.size() > 0) {
     
      //========== decide if the top in the heap should be pruned
View Full Code Here

    int[] sourceRHS = {24, -1, 42, 738};
    int[] targetRHS = {-1, 7, 8};
    float[] featureScores = {-2.35f, -1.78f, -0.52f};
    int arity = 1;
   
    Rule dummyRule = new BilingualRule(lhs, sourceRHS, targetRHS, featureScores, arity);
   
    Assert.assertEquals(featureFunction.estimateLogP(dummyRule, -1), ArityPhrasePenaltyFF.ALPHA);
   
  }
View Full Code Here

    if(dt.getAntNodes()!=null)
      for(HGNode antNode : dt.getAntNodes())
        collectHGNodePosteriorCount(antNode);
   
    //### deduction-specific operation
    Rule rl = dt.getRule();
    if(rl!=null){
      //TODO: underflow problem
      //TODO: what about OOV rule
      //TODO: synchronization problem
      //System.out.println("postProb: " + p_inside_outside.get_deduction_posterior_prob(dt, parent_item));
View Full Code Here

  }
 
//  O(n^2) comparisons
  protected void getConfusionFromRules(List<Rule> rules, List<Double> probs){
    for(int i=0; i<rules.size(); i++){
      Rule rule1= rules.get(i);
      for(int j=0; j<rules.size(); j++){
        Rule rule2= rules.get(j);
       
        /**use the probability of rule j
         **/
        processRulePair(rule1, rule2, probs.get(j));
      }
View Full Code Here

TOP

Related Classes of joshua.decoder.ff.tm.Rule

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.