Exemplo n.º 1
0
void ChartHypothesis::CleanupArcList()
{
  // point this hypo's main hypo to itself
  m_winningHypo = this;

  if (!m_arcList) return;

  /* keep only number of arcs we need to create all n-best paths.
   * However, may not be enough if only unique candidates are needed,
   * so we'll keep all of arc list if nedd distinct n-best list
   */
  AllOptions const& opts = StaticData::Instance().options();
  const StaticData &staticData = StaticData::Instance();
  size_t nBestSize = opts.nbest.nbest_size;
  bool distinctNBest = (opts.nbest.only_distinct
                        || opts.mbr.enabled
                        || opts.output.NeedSearchGraph()
                        || !opts.output.SearchGraphHG.empty());

  if (!distinctNBest && m_arcList->size() > nBestSize) {
    // prune arc list only if there too many arcs
    NTH_ELEMENT4(m_arcList->begin()
                 , m_arcList->begin() + nBestSize - 1
                 , m_arcList->end()
                 , CompareChartHypothesisTotalScore());

    // delete bad ones
    ChartArcList::iterator iter;
    for (iter = m_arcList->begin() + nBestSize ; iter != m_arcList->end() ; ++iter) {
      ChartHypothesis *arc = *iter;
      delete arc;
    }
    m_arcList->erase(m_arcList->begin() + nBestSize
                     , m_arcList->end());
  }

  // set all arc's main hypo variable to this hypo
  ChartArcList::iterator iter = m_arcList->begin();
  for (; iter != m_arcList->end() ; ++iter) {
    ChartHypothesis *arc = *iter;
    arc->SetWinningHypo(this);
  }

  //cerr << m_arcList->size() << " ";
}
Exemplo n.º 2
0
void ChartHypothesis::CleanupArcList()
{
    // point this hypo's main hypo to itself
    m_winningHypo = this;

    if (!m_arcList) return;

    /* keep only number of arcs we need to create all n-best paths.
     * However, may not be enough if only unique candidates are needed,
     * so we'll keep all of arc list if nedd distinct n-best list
     */
    const StaticData &staticData = StaticData::Instance();
    size_t nBestSize = staticData.GetNBestSize();
    bool distinctNBest = staticData.GetDistinctNBest() || staticData.UseMBR() || staticData.GetOutputSearchGraph();

    if (!distinctNBest && m_arcList->size() > nBestSize) {
        // prune arc list only if there too many arcs
        nth_element(m_arcList->begin()
                    , m_arcList->begin() + nBestSize - 1
                    , m_arcList->end()
                    , CompareChartChartHypothesisTotalScore());

        // delete bad ones
        ChartArcList::iterator iter;
        for (iter = m_arcList->begin() + nBestSize ; iter != m_arcList->end() ; ++iter) {
            ChartHypothesis *arc = *iter;
            ChartHypothesis::Delete(arc);
        }
        m_arcList->erase(m_arcList->begin() + nBestSize
                         , m_arcList->end());
    }

    // set all arc's main hypo variable to this hypo
    ChartArcList::iterator iter = m_arcList->begin();
    for (; iter != m_arcList->end() ; ++iter) {
        ChartHypothesis *arc = *iter;
        arc->SetWinningHypo(this);
    }

    //cerr << m_arcList->size() << " ";
}