Package joshua.decoder.hypergraph

Examples of joshua.decoder.hypergraph.HGNode


 
 
  //get the 1best tree hg, the 1-best is ranked by the split hypergraph, but the return hypergraph is in the form of the original hg 
  public HyperGraph get_1best_tree_hg(HyperGraph original_hg, HashMap<HGNode, ArrayList<VirtualItem>> g_tbl_split_virtual_items){
    VirtualItem virutal_goal_item =  get_virtual_goal_item(original_hg, g_tbl_split_virtual_items);
    HGNode onebest_goal_item = clone_item_with_best_deduction(virutal_goal_item);   
    HyperGraph res = new HyperGraph(onebest_goal_item, -1, -1, original_hg.sentID, original_hg.sentLen);//TODO: number of items/deductions
    get_1best_tree_item(virutal_goal_item, onebest_goal_item);
    return res;
  }
View Full Code Here


  private void get_1best_tree_item(VirtualItem virtual_it, HGNode onebest_item){ 
    VirtualDeduction virtual_dt = virtual_it.best_virtual_deduction;
    if(virtual_dt.l_ant_virtual_items!=null)
      for(int i=0; i< virtual_dt.l_ant_virtual_items.size(); i++){
        VirtualItem ant_it = (VirtualItem) virtual_dt.l_ant_virtual_items.get(i);
        HGNode new_it = clone_item_with_best_deduction(ant_it);
        onebest_item.bestHyperedge.getAntNodes().set(i, new_it);
        get_1best_tree_item(ant_it,new_it)
      }   
  } 
View Full Code Here

      }   
  } 
 
  //TODO: tbl_states
  private static HGNode clone_item_with_best_deduction(VirtualItem virtual_it){
    HGNode original_it = virtual_it.p_item;
    ArrayList<HyperEdge> l_deductions = new ArrayList<HyperEdge>();   
    HyperEdge clone_dt = clone_deduction(virtual_it.best_virtual_deduction);
    l_deductions.add(clone_dt);
    return new HGNode(original_it.i, original_it.j, original_it.lhs,  l_deductions, clone_dt, original_it.getDPStates())
  }
View Full Code Here

    private void redo_combine(HyperEdge cur_dt, HashMap<String, VirtualItem> virtual_item_sigs, HGNode parent_item){
      List<HGNode> l_ant_items = cur_dt.getAntNodes();
      if(l_ant_items!=null){
        // arity: one
        if(l_ant_items.size() == 1){
          HGNode it = l_ant_items.get(0);
          ArrayList<VirtualItem> l_virtual_items = g_tbl_split_virtual_items.get(it);       
          for(VirtualItem ant_virtual_item : l_virtual_items) {
            //used in combination
            ArrayList<VirtualItem> l_ant_virtual_item =
              new ArrayList<VirtualItem>();
            l_ant_virtual_item.add(ant_virtual_item);
            process_one_combination_nonaxiom(parent_item, virtual_item_sigs,
                cur_dt,  l_ant_virtual_item);
          }
        // arity: two
        } else if (l_ant_items.size() == 2) {
          HGNode it1 = l_ant_items.get(0);
          HGNode it2 = l_ant_items.get(1);
          ArrayList<VirtualItem> l_virtual_items1 = g_tbl_split_virtual_items.get(it1);
          ArrayList<VirtualItem> l_virtual_items2 = g_tbl_split_virtual_items.get(it2);
          for (VirtualItem virtual_it1 : l_virtual_items1) {
            for (VirtualItem virtual_it2 : l_virtual_items2) {
              // used in combination
View Full Code Here

      for(int c=0; c<enWords.length; c++){
          int curID = enWords[c];
          if(symbolTable.isNonterminal(curID)==true){//non-terminal words         
            //== get the left and right context
            int index = symbolTable.getTargetNonterminalIndex(curID);
            HGNode antNode =  antNodes.get(index);
            NgramDPState state     = (NgramDPState) antNode.getDPState(this.ngramStateID);
            //System.out.println("lm_feat_is: " + this.lm_feat_id + " ; state is: " + state);
            List<Integer>   leftContext = state.getLeftLMStateWords();
            List<Integer>   rightContext = state.getRightLMStateWords();
          if (leftContext.size() != rightContext.size()) {
            System.out.println("getAllNgrams: left and right contexts have unequal lengths");
View Full Code Here

   * hyperedges only "goal bin" should call this function
   */
  //note that thei nput bin is  bin[0][n], not the goal bin
  void transitToGoal(Cell bin, List<FeatureFunction> featureFunctions, int sentenceLength) {
    this.sortedNodes = new ArrayList<HGNode>();
    HGNode goalItem = null;
   
    for (HGNode antNode : bin.getSortedNodes()) {
      if (antNode.lhs == this.goalSymID) {
        double logP = antNode.bestHyperedge.bestDerivationLogP;
        List<HGNode> antNodes = new ArrayList<HGNode>();
        antNodes.add(antNode);
       
        double finalTransitionLogP = ComputeNodeResult.computeCombinedTransitionLogP(featureFunctions, null, antNodes, 0, sentenceLength, null, this.chart.segmentID);
                   
        List<HGNode> previousItems = new ArrayList<HGNode>();
        previousItems.add(antNode);
       
        HyperEdge dt = new HyperEdge(null, logP + finalTransitionLogP, finalTransitionLogP, previousItems, null);
               
        if (null == goalItem) {
          goalItem = new HGNode(0, sentenceLength + 1, this.goalSymID, null, dt, logP + finalTransitionLogP);
          this.sortedNodes.add(goalItem);
        } else {
          goalItem.addHyperedgeInNode(dt);
        }
      } // End if item.lhs == this.goalSymID
    } // End foreach Item in bin.get_sorted_items()
   
   
View Full Code Here

   * */
  HGNode addHyperEdgeInCell(
    ComputeNodeResult result, Rule rule, int i, int j,
    List<HGNode> ants, SourcePath srcPath, boolean noPrune
  ) {
    HGNode res = null;
   
    HashMap<Integer,DPState> dpStates = result.getDPStates();
    double expectedTotalLogP  = result.getExpectedTotalLogP(); // including outside estimation
    double transitionLogP    = result.getTransitionTotalLogP();
    double finalizedTotalLogP = result.getFinalizedTotalLogP();
   
   
   
    if(noPrune==false && beamPruner!=null &&  beamPruner.relativeThresholdPrune(expectedTotalLogP)){//the hyperedge should be pruned
      this.chart.nPreprunedEdges++;
      res = null;
    }else{
      HyperEdge dt = new HyperEdge(rule, finalizedTotalLogP, transitionLogP, ants, srcPath);
      res = new HGNode(i, j, rule.getLHS(), dpStates, dt, expectedTotalLogP);
     
      /** each node has a list of hyperedges,
       * need to check whether the node is already exist,
       * if yes, just add the hyperedges, this may change the best logP of the node
       * */
      HGNode oldNode = this.nodesSigTbl.get( res.getSignature() );
      if (null != oldNode) { // have an item with same states, combine items
        this.chart.nMerged++;
       
        /** the position of oldItem in this.heapItems
         *  may change, basically, we should remove the
         *  oldItem, and re-insert it (linear time), this is too expense)
         **/
        if ( res.getPruneLogP() > oldNode.getPruneLogP() ) {//merget old to new: semiring plus         

          if(beamPruner!=null){
            oldNode.setDead();// this.heapItems.remove(oldItem);
            beamPruner.incrementDeadObjs();
          }
         
          res.addHyperedgesInNode(oldNode.hyperedges);
          addNewNode(res, noPrune); //this will update the HashMap, so that the oldNode is destroyed
         
        } else {//merge new to old, does not trigger pruningItems
          oldNode.addHyperedgesInNode(res.hyperedges);
        }
       
      } else { // first time item
        this.chart.nAdded++; // however, this item may not be used in the future due to pruning in the hyper-graph
        addNewNode(res, noPrune);
View Full Code Here

    }
    int qtyAdditionsToQueue = 0;
    ArrayList<HGNode> queue  = new ArrayList<HGNode>( chartBin.getSortedNodes() );
   
    while (queue.size() > 0) {
      HGNode node = queue.remove(0);
      for(Grammar gr : grs){
        if (! gr.hasRuleForSpan(i, j, foreignSentenceLength))
          continue;
       
        Trie childNode = gr.getTrieRoot().matchOne(node.lhs); // match rule and complete part
        if (childNode != null
          && childNode.getRules() != null
          && childNode.getRules().getArity() == 1) { // have unary rules under this trienode
         
          ArrayList<HGNode> antecedents = new ArrayList<HGNode>();
          antecedents.add(node);
          List<Rule> rules = childNode.getRules().getSortedRules();
         
          for (Rule rule : rules) { // for each unary rules               
            ComputeNodeResult states = new ComputeNodeResult(this.featureFunctions, rule, antecedents, i, j, new SourcePath(), stateComputers, this.segmentID);
            HGNode resNode = chartBin.addHyperEdgeInCell(states, rule, i, j, antecedents, new SourcePath(), true);
            if (null != resNode) {
              queue.add(resNode);
              qtyAdditionsToQueue++;
            }
          }
View Full Code Here

            ArrayList<HGNode> queue
                    = new ArrayList<HGNode>(chartCell.getSortedNodes());


            while (queue.size() > 0) {
              HGNode item = (HGNode)queue.remove(0);
                Trie child_tnode = gr.getTrieRoot().matchOne(item.lhs);//match rule and complete part
                if (child_tnode != null
                && child_tnode.getRules() != null
                && child_tnode.getRules().getArity() == 1) {//have unary rules under this trienode
                        ArrayList<HGNode> l_ants = new ArrayList<HGNode>();
                        l_ants.add(item);
                        List<Rule> rules =
                                child_tnode.getRules().getSortedRules();

                        for (Rule rule : rules){//for each unary rules
                          ComputeNodeResult states = new ComputeNodeResult(this.featureFunctions, rule, l_ants, i, j, new SourcePath(), stateComputers, this.segmentID);
                            HGNode res_item = chartCell.addHyperEdgeInCell(states, rule, i, j, l_ants, new SourcePath(), false);
                            if (null != res_item) {
                                    queue.add(res_item);
                                    qtyAdditionsToQueue++;
                            }
                        }
View Full Code Here

    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
      tem_c++;
View Full Code Here

TOP

Related Classes of joshua.decoder.hypergraph.HGNode

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.