Ejemplo n.º 1
0
Clue Letterbox::mathClue(const QString &clue)
{
	Dict::WordList clueWords = QuackleIO::DictFactory::querier()->query(clue);
	QString word = (*clueWords.begin()).word;

	int bestChew = 0;
	QString ret;

	for (int i = 0; i < word.length(); i++)
	{
		QString query = word.left(i) + word.right(word.length() - i - 1);
		Dict::WordList words = QuackleIO::DictFactory::querier()->query(query);
		for (Dict::WordList::iterator it = words.begin(); it != words.end(); ++it)
		{
			int chew = chewScore((*it).word, word);
			if (chew > bestChew)
			{
				bestChew = chew;
				ret = (*it).word + " + " + word.at(i);
			}
		}
	}

	if (bestChew > 2)
		return Clue(ret);

	return Clue(arrangeLettersForUser(word));
}
Ejemplo n.º 2
0
void PlayabilityFilter::apply()
{
    int minimumRank = m_minRankSpinner->value();
    int maximumRank = m_maxRankSpinner->value();
    if (maximumRank == 0)
        maximumRank = INT_MAX;

    const bool useProb = m_dialog->flags() & ListerDialog::ProbabilityInsteadOfPlayability;

    QMap<QString, Dict::WordList> map(m_dialog->anagramMap());

    Dict::WordList intermediateList;

    QMap<QString, Dict::WordList>::Iterator end = map.end();
    for (QMap<QString, Dict::WordList>::Iterator it = map.begin(); it != end; ++it)
    {
        Dict::Word newEntry;
        newEntry.word = it.key();

        for (Dict::WordList::Iterator extIt = it.value().begin(); extIt != it.value().end(); ++extIt)
        {
            if (useProb)
                newEntry.probability += (*extIt).probability;
            else
                newEntry.playability += (*extIt).playability;
        }

        intermediateList.append(newEntry);
    }

    int index = 0;

    if (useProb)
        intermediateList.setSortBy(Dict::WordList::Probability);
    else
        intermediateList.setSortBy(Dict::WordList::Playability);
    qSort(intermediateList);

    Dict::WordList filteredList;

    Dict::WordList::Iterator intermediateEnd = intermediateList.end();
    for (Dict::WordList::Iterator it = intermediateList.begin(); it != intermediateEnd; ++it)
    {
        ++index;

        if (index > maximumRank)
            break;

        if (index < minimumRank)
            continue;

        filteredList += map[(*it).word];
    }

    m_dialog->setWordList(filteredList);
}
Ejemplo n.º 3
0
void ClueResult::setWordList(Dict::WordList answers)
{
	for (Dict::WordList::iterator it = answers.begin(); it != answers.end(); ++it)
	{
		bool isAnswerInOurWords = false;
		for (WordResultList::iterator wrIt = words.begin(); wrIt != words.end(); ++wrIt)
		{
			if ((*it).word == (*wrIt).word)
			{
				isAnswerInOurWords = true;
				break;
			}
		}

		if (!isAnswerInOurWords)
			words.append(WordResult((*it).word));	
	}
}
Ejemplo n.º 4
0
QString HTMLRepresentation::htmlForWordList(const Dict::WordList &wordList)
{
	if (wordList.isEmpty())
		return QString::null;

	QString html = QString("<center><table border=1 cellspacing=%1 cellpadding=%2>").arg(m_tableSpacing).arg(m_tablePadding);

	bool hasFrontExtensionColumn = false;
	bool hasBackExtensionColumn = false;

	Dict::WordList::ConstIterator end = wordList.end();
	for (Dict::WordList::ConstIterator it = wordList.begin(); it != end; ++it)
	{
		if (!(tableOfExtensions((*it).getFrontExtensionList()).isEmpty()))		
			hasFrontExtensionColumn = true;
		if (!(tableOfExtensions((*it).getBackExtensionList()).isEmpty()))		
			hasBackExtensionColumn = true;
	}

	for (Dict::WordList::ConstIterator it = wordList.begin(); it != end; ++it)
	{
		html += "<tr>";

		if (hasFrontExtensionColumn)
			html += "<td align=right>" + tableOfExtensions((*it).getFrontExtensionList()) + "</td>";

		html += "<td align=center>" + htmlForSolution(*it) + "</td>";

		if (hasBackExtensionColumn)
			html += "<td align=left>" + tableOfExtensions((*it).getBackExtensionList()) + "</td>";

		html += "</tr>";
	}
	html += "</table></center><font size=\"-7\"><br></font>\n";
     	
	return html;
}