Ejemplo n.º 1
0
void ParserCKYBest::parse(Chart& chart) const
{
  bool isroot = chart.get_size() == 1;
  for(unsigned i = 0; i < chart.get_size(); ++i) {
    //    std::cout << "initialising position: " << i << std::endl;
    add_unary_init(chart.access(i,i),isroot);
    //    std::cout << chart.access(i,i) << std::endl;
  }

  process_internal_rules(chart);
}
Ejemplo n.º 2
0
void ParserCKYBest::process_internal_rules(Chart& chart) const
{
  unsigned sent_size=chart.get_size();
  for (unsigned span = 2; span <= sent_size; ++span) {
    unsigned end_of_begin=sent_size-span;
    for (unsigned begin=0; begin <= end_of_begin; ++begin) {
    	unsigned end = begin + span -1;

      //      std::cout << "begin: " << begin << ", end: " << end << std::endl;

    	Cell& result_cell = chart.access(begin,end);

    	if(!result_cell.is_closed()) {
    		// look for all possible new edges
    		for (unsigned m = begin; m < end; ++m) {
    			const Cell& left_cell = chart.access(begin,m);
    			if(!left_cell.is_closed()) {
    				const Cell& right_cell = chart.access(m+1,end);
    				if( !right_cell.is_closed())
    					get_candidates(left_cell,right_cell,result_cell);
    			}
    		}
    		// std::cout << result_cell << std::endl;

    		add_unary(result_cell, span == sent_size);

	//	result_cell.apply_beam();
      }
      // std::cout << result_cell << std::endl;
    }
  }
}