当前位置: 首页>>代码示例>>C++>>正文


C++ WordsBitmap::GetLastPos方法代码示例

本文整理汇总了C++中WordsBitmap::GetLastPos方法的典型用法代码示例。如果您正苦于以下问题:C++ WordsBitmap::GetLastPos方法的具体用法?C++ WordsBitmap::GetLastPos怎么用?C++ WordsBitmap::GetLastPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WordsBitmap的用法示例。


在下文中一共展示了WordsBitmap::GetLastPos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

float SquareMatrix::CalcFutureScore2( WordsBitmap const &bitmap, size_t startPos, size_t endPos ) const
{
  const size_t notInGap= numeric_limits<size_t>::max();
  float futureScore = 0.0f;
  size_t startGap = bitmap.GetFirstGapPos();
  if (startGap == NOT_FOUND) return futureScore; // everything filled

  // start loop at first gap
  size_t startLoop = startGap+1;
  if (startPos == startGap) { // unless covered by phrase
    startGap = notInGap;
    startLoop = endPos+1; // -> postpone start
  }

  size_t lastCovered = bitmap.GetLastPos();
  if (endPos > lastCovered || lastCovered == NOT_FOUND) lastCovered = endPos;

  for(size_t currPos = startLoop; currPos <= lastCovered ; currPos++) {
    // start of a new gap?
    if(startGap == notInGap && bitmap.GetValue(currPos) == false && (currPos < startPos || currPos > endPos)) {
      startGap = currPos;
    }
    // end of a gap?
    else if(startGap != notInGap && (bitmap.GetValue(currPos) == true || (startPos <= currPos && currPos <= endPos))) {
      futureScore += GetScore(startGap, currPos - 1);
      startGap = notInGap;
    }
  }
  // coverage ending with gap?
  if (lastCovered != bitmap.GetSize() - 1) {
    futureScore += GetScore(lastCovered+1, bitmap.GetSize() - 1);
  }

  return futureScore;
}
开发者ID:ksingla025,项目名称:mosesdecoder,代码行数:35,代码来源:SquareMatrix.cpp

示例2: Check

//! check if the current hypothesis extension violates reordering constraints
bool ReorderingConstraint::Check( const WordsBitmap &bitmap, size_t startPos, size_t endPos ) const
{
  // nothing to be checked, we are done
  if (! IsActive() ) return true;

  VERBOSE(3,"CHECK " << bitmap << " " << startPos << "-" << endPos);

  // check walls
  size_t firstGapPos = bitmap.GetFirstGapPos();
  // filling first gap -> no wall violation possible
  if (firstGapPos != startPos) {
    // if there is a wall before the last word,
    // we created a gap while moving through wall
    // -> violation
    for( size_t pos = firstGapPos; pos < endPos; pos++ ) {
      if( GetWall( pos ) ) {
        VERBOSE(3," hitting wall " << pos << std::endl);
        return false;
      }
    }
  }

  // monotone -> no violation possible
  size_t lastPos = bitmap.GetLastPos();
  if ((lastPos == NOT_FOUND && startPos == 0) || // nothing translated
      (firstGapPos > lastPos &&  // no gaps
       firstGapPos == startPos)) { // translating first empty word
    VERBOSE(3," montone, fine." << std::endl);
    return true;
  }

  // check zones
  for(size_t z = 0; z < m_zone.size(); z++ ) {
    const size_t startZone = m_zone[z][0];
    const size_t endZone = m_zone[z][1];

    // fine, if translation has not reached zone yet and phrase outside zone
    if (lastPos < startZone && ( endPos < startZone || startPos > endZone ) ) {
      continue;
    }

    // already completely translated zone, no violations possible
    if (firstGapPos > endZone) {
      continue;
    }

    // some words are translated beyond the start
    // let's look closer if some are in the zone
    size_t numWordsInZoneTranslated = 0;
    if (lastPos >= startZone) {
      for(size_t pos = startZone; pos <= endZone; pos++ ) {
        if( bitmap.GetValue( pos ) ) {
          numWordsInZoneTranslated++;
        }
      }
    }

    // all words in zone translated, no violation possible
    if (numWordsInZoneTranslated == endZone-startZone+1) {
      continue;
    }

    // flag if this is an active zone
    bool activeZone = (numWordsInZoneTranslated > 0);

    // fine, if zone completely untranslated and phrase outside zone
    if (!activeZone && ( endPos < startZone || startPos > endZone ) ) {
      continue;
    }

    // violation, if phrase completely outside active zone
    if (activeZone && ( endPos < startZone || startPos > endZone ) ) {
      VERBOSE(3," outside active zone" << std::endl);
      return false;
    }

    // ok, this is what we know now:
    // * the phrase is in the zone (at least partially)
    // * either zone is already active, or it becomes active now


    // check, if we are setting us up for a dead end due to distortion limits
    int distortionLimit = StaticData::Instance().GetMaxDistortion();
    if (startPos != firstGapPos && endZone-firstGapPos >= distortionLimit) {
      VERBOSE(3," dead end due to distortion limit" << std::endl);
      return false;
    }

    // let us check on phrases that are partially outside

    // phrase overlaps at the beginning, always ok
    if (startPos <= startZone) {
      continue;
    }

    // phrase goes beyond end, has to fill zone completely
    if (endPos > endZone) {
      if (endZone-startPos+1 < // num. words filled in by phrase
          endZone-startZone+1-numWordsInZoneTranslated) { // num. untranslated
//.........这里部分代码省略.........
开发者ID:MarwenAZOUZI,项目名称:mosesdecoder,代码行数:101,代码来源:ReorderingConstraint.cpp


注:本文中的WordsBitmap::GetLastPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。