void PriorTrickWidget::paintComponent( const agui::PaintEvent &paintEvent )
	{
		paintEvent.graphics()->drawText(
			agui::Point(alignString(m_priorTrickText,
			agui::ALIGN_CENTER),0),m_priorTrickText.c_str(),
			getFontColor(),getFont());

		//not interested if too few cards
		if(m_cards.size() < 3)
			return;

		int cutThroatYOffset = 0;
		if(m_cards.size() == 3)
		{
			agui::Dimension heartSz = getSuitImgSize(Card::HEARTS);
			cutThroatYOffset = (heartSz.getHeight() * m_scale * m_imgScale) / 2;
		}

		int newVGap = m_vgap * m_scale;
		int newHGap = m_hgap * m_scale;

		renderCard(agui::ALIGN_BOTTOM_CENTER,m_cards[0],0,-newVGap - cutThroatYOffset,
			paintEvent);
		renderCard(agui::ALIGN_MIDDLE_LEFT,m_cards[1],newHGap,
			(newVGap / 2) - cutThroatYOffset,paintEvent);

		if(m_cards.size() > 3)
		{
			renderCard(agui::ALIGN_TOP_CENTER,m_cards[2],0,
				getFont()->getLineHeight() + (newVGap / 2) - cutThroatYOffset,paintEvent);
		}

		renderCard(agui::ALIGN_MIDDLE_RIGHT,m_cards.back(),-newHGap,
			(newVGap / 2) - cutThroatYOffset,paintEvent);
	}
Exemple #2
0
bool RuleTableLoaderStandard::Load(FormatType format
                                , const std::vector<FactorType> &input
                                , const std::vector<FactorType> &output
                                , const std::string &inFile
                                , const std::vector<float> &weight
                                , size_t /* tableLimit */
                                , const LMList &languageModels
                                , const WordPenaltyProducer* wpProducer
                                , RuleTableTrie &ruleTable)
{
  PrintUserTime(string("Start loading text SCFG phrase table. ") + (format==MosesFormat?"Moses ":"Hiero ") + " format");

  const StaticData &staticData = StaticData::Instance();
  const std::string& factorDelimiter = staticData.GetFactorDelimiter();

  string lineOrig;
  size_t count = 0;

  std::ostream *progress = NULL;
  IFVERBOSE(1) progress = &std::cerr;
  util::FilePiece in(inFile.c_str(), progress);

  // reused variables
  vector<float> scoreVector;
  StringPiece line;
  std::string hiero_before, hiero_after;

  while(true) {
    try {
      line = in.ReadLine();
    } catch (const util::EndOfFileException &e) { break; }

    if (format == HieroFormat) { // inefficiently reformat line
      hiero_before.assign(line.data(), line.size());
      ReformatHieroRule(hiero_before, hiero_after);
      line = hiero_after;
    }

    util::TokenIter<util::MultiCharacter> pipes(line, "|||");
    StringPiece sourcePhraseString(*pipes);
    StringPiece targetPhraseString(*++pipes);
    StringPiece scoreString(*++pipes);
    StringPiece alignString(*++pipes);
    // TODO(bhaddow) efficiently handle default instead of parsing this string every time.  
    StringPiece ruleCountString = ++pipes ? *pipes : StringPiece("1 1");
    
    if (++pipes) {
      stringstream strme;
      strme << "Syntax error at " << ruleTable.GetFilePath() << ":" << count;
      UserMessage::Add(strme.str());
      abort();
    }

    bool isLHSEmpty = (sourcePhraseString.find_first_not_of(" \t", 0) == string::npos);
    if (isLHSEmpty && !staticData.IsWordDeletionEnabled()) {
      TRACE_ERR( ruleTable.GetFilePath() << ":" << count << ": pt entry contains empty target, skipping\n");
      continue;
    }

    scoreVector.clear();
    for (util::TokenIter<util::AnyCharacter, true> s(scoreString, " \t"); s; ++s) {
      char *err_ind;
      scoreVector.push_back(strtod(s->data(), &err_ind));
      UTIL_THROW_IF(err_ind == s->data(), util::Exception, "Bad score " << *s << " on line " << count);
    }
    const size_t numScoreComponents = ruleTable.GetFeature()->GetNumScoreComponents();
    if (scoreVector.size() != numScoreComponents) {
      stringstream strme;
      strme << "Size of scoreVector != number (" << scoreVector.size() << "!="
            << numScoreComponents << ") of score components on line " << count;
      UserMessage::Add(strme.str());
      abort();
    }

    // parse source & find pt node

    // constituent labels
    Word sourceLHS, targetLHS;

    // source
    Phrase sourcePhrase( 0);
    sourcePhrase.CreateFromStringNewFormat(Input, input, sourcePhraseString, factorDelimiter, sourceLHS);

    // create target phrase obj
    TargetPhrase *targetPhrase = new TargetPhrase(Output);
    targetPhrase->CreateFromStringNewFormat(Output, output, targetPhraseString, factorDelimiter, targetLHS);
    targetPhrase->SetSourcePhrase(sourcePhrase);

    // rest of target phrase
    targetPhrase->SetAlignmentInfo(alignString, sourcePhrase);
    targetPhrase->SetTargetLHS(targetLHS);
    
    targetPhrase->SetRuleCount(ruleCountString, scoreVector[0]);
    //targetPhrase->SetDebugOutput(string("New Format pt ") + line);
    
    // component score, for n-best output
    std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),TransformScore);
    std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),FloorScore);

    targetPhrase->SetScoreChart(ruleTable.GetFeature(), scoreVector, weight, languageModels,wpProducer);

    TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(ruleTable, sourcePhrase, *targetPhrase, sourceLHS);
    phraseColl.Add(targetPhrase);

    count++;
  }

  // sort and prune each target phrase collection
  SortAndPrune(ruleTable);

  return true;
}
	void PopUpMenu::paintComponent( const agui::PaintEvent &paintEvent )
	{
		int totalHeight = 0;
		agui::Color regularColor = agui::Color(
			getFontColor().getR(),getFontColor().getG(),getFontColor().getB(),getOpacity());
		agui::Color disabledColor = agui::Color(
			getDisabledFontColor().getR(),getDisabledFontColor().getG(),
			getDisabledFontColor().getB(),getOpacity());

		for(int i = 0; i < getLength(); ++i)
		{
			int w = 0;
			agui::PopUpMenuItem* item = getItemAt(i);

			if(i == getSelectedIndex() && item->getItemType() != agui::PopUpMenuItem::SEPARATOR)
			{
				paintEvent.graphics()->drawNinePatchImage(
					m_highlightImg,agui::Point(0,totalHeight),
					agui::Dimension(getInnerWidth(),getItemHeight()),getOpacity());
			}

			//draw the icon
			if(isShowingIcon())
			{
				if(item->getIcon())
				{
					paintEvent.graphics()->
						drawImage(item->getIcon(),getIconPosition(i,totalHeight),getOpacity());
				}

				w += getIconWidth();
			}

			if(item->isSeparator())
			{
				paintEvent.graphics()->drawLine(
					agui::Point(w,totalHeight + (getItemHeight(item) / 2)),
					agui::Point(getInnerWidth(),totalHeight + (getItemHeight(item) / 2)),
					agui::Color(90,90,90));

				paintEvent.graphics()->drawLine(
					agui::Point(w,totalHeight + (getItemHeight(item) / 2) + 1),
					agui::Point(getInnerWidth(),totalHeight + (getItemHeight(item) / 2) + 1),
					agui::Color(200,200,200));
			}

			w += getStartTextGap();

			agui::Color* fontColor = item->isEnabled() ? &regularColor : &disabledColor;

			paintEvent.graphics()->drawText(agui::Point(w,getTextCenter() + totalHeight),
				item->getText().c_str(),
				*fontColor,
				getFont());

			w+= getMiddleTextGap();

			agui::Point shortcutPoint = alignString(item->getShortcutText(),agui::ALIGN_MIDDLE_RIGHT);
			shortcutPoint.setX(shortcutPoint.getX() - getEndTextGap());
			shortcutPoint.setY(getTextCenter() + totalHeight);


			paintEvent.graphics()->drawText(shortcutPoint,
				item->getShortcutText().c_str(),*fontColor,
				getFont());

			if(item->isSubMenu())
			{
				paintEvent.graphics()->drawImage(m_subArrowImg,
					createAlignedPosition(agui::ALIGN_MIDDLE_CENTER,
					agui::Rectangle(getInnerWidth() - getEndTextGap(),
					totalHeight,getEndTextGap(),getItemHeight()),
					agui::Dimension(m_subArrowImg->getWidth(),m_subArrowImg->getHeight())),
					getOpacity());
			}

			totalHeight += getItemHeight(item);
		}
	}