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

    if(l_virtual_items.size()<=0){//TODO     
      System.out.println("no valid trees");
    }else{
      System.out.println("has valid trees, " + l_virtual_items.size());     
      //create a new hypergraph
      HGNode colone_goal_item = clone_item(hg.goalNode);
      hg_filtered = new HyperGraph(colone_goal_item, -1, -1, hg.sentID, hg.sentLen);
      colone_goal_item.hyperedges.clear();
      for(VirtualItem fit : l_virtual_items){
        if(fit.p_item!=hg.goalNode){System.out.println("wrong item"); System.exit(0);}
        for(VirtualDeduction fdt : fit.l_virtual_deductions){
View Full Code Here

    for(HyperEdge dt : it_in.hyperedges){ 
      if(dt==it_in.bestHyperedge) best_dt = dt;        
      HyperEdge clone_dt = clone_deduction(dt);
      l_deductions.add(clone_dt);
    }
    return new HGNode(it_in.i, it_in.j, it_in.lhs,  l_deductions, best_dt, it_in.getDPStates() )
  }
View Full Code Here

    //end
   
    create_start_pos_index(ref_sent_wrds);
   
    System.out.println("goal_item has " + hg.goalNode.hyperedges.size() );
    HGNode new_goal_node = filter_item(hg.goalNode);
    if(new_goal_node==null){
      System.out.println("The hypergraph has been fully filterd out, must be wrong");
      System.exit(0);
    }
    System.out.println("Finished filtering the hypergraph");
View Full Code Here

          if(best_survive_deduction ==null || best_survive_deduction.bestDerivationLogP>new_edge.bestDerivationLogP)
            best_survive_deduction = new_edge;
        }
      }
     
      HGNode new_node = null;
      if(should_filter==false){//survive
        new_node = new HGNode(it.i, it.j, it.lhs, l_survive_deductions, best_survive_deduction, it.getDPStates());
      }

      tbl_processed_items.put(it,new_node);
      //System.out.println("res=" + res+ "; old_n_deducts=" + old_num_deductions + "; new="+ it.l_deductions.size());
      return new_node;
View Full Code Here

      double bestLogP = dt.getTransitionLogP(false);
      ArrayList<HGNode> l_ant_items = null;
      if(dt.getAntNodes()!=null){
        l_ant_items = new ArrayList<HGNode>();
        for(HGNode ant_it : dt.getAntNodes()){
          HGNode new_node = filter_item(ant_it);
          if(new_node==null){//the edge should be filtered out as long as one item is filtered out
            should_filter = true;
            break;
          }else{
            bestLogP += new_node.bestHyperedge.bestDerivationLogP;
View Full Code Here

      for(int c=0; c<en_words.length; c++){
          int c_id = en_words[c];
          if(p_symbol.isNonterminal(c_id)==true){
            //## get the left and right context
            int index= p_symbol.getTargetNonterminalIndex(c_id);
            HGNode ant_item = (HGNode) dt.getAntNodes().get(index);
            NgramDPState state     = (NgramDPState) ant_item.getDPState(this.ngramStateID);
          List<Integer>   l_context = state.getLeftLMStateWords();
          List<Integer>   r_context = state.getRightLMStateWords();
          if (l_context.size() != r_context.size()) {
            System.out.println("LMModel>>lookup_words1_equv_state: left and right contexts have unequal lengths");
            System.exit(1);
          }
         
          for(int t : l_context)//always have l_context
              words.add(t);               
           
            if(r_context.size()>=baseline_lm_order-1){//the right and left are NOT overlapping
              if(match_a_span(words)==false)//no match
                return true;//filter out
                   
              words.clear();//start a new chunk; the sequence stops whenever the right-lm-state jumps in (i.e., having eclipsed words) 
              for(int t : r_context)
                words.add(t);           
            }
          }else{
            words.add(c_id);
          }
        }
      if(words.size()>0){
        if(match_a_span(words)==false)//no match
          return true;//filter out
      }
    }else{//hyperedges under goal item
      if(dt.getAntNodes().size()!=1){System.out.println("error deduction under goal item have more than one item"); System.exit(0);}
      HGNode ant_item = (HGNode) dt.getAntNodes().get(0);
      NgramDPState state     = (NgramDPState) ant_item.getDPState(this.ngramStateID);
      List<Integer>   l_context = state.getLeftLMStateWords();
      List<Integer>   r_context = state.getRightLMStateWords();
      if(matchLeftOrRightMostSpan(l_context, true)==false ||
         matchLeftOrRightMostSpan(r_context, false)==false )//the left-most or right-most word does not match
        return true;
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.