예제 #1
2
파일: lister.cpp 프로젝트: liesen/quackle
void NumAnagramsFilter::apply()
{
    int numTwlAnagrams = m_twlAnagramsSpinner->value();
    int numOswOnlyAnagrams = m_oswOnlyAnagramsSpinner->value();

    Dict::WordList filteredList;

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

    Dict::WordList::Iterator end = m_dialog->wordList().end();
    for (Dict::WordList::Iterator it = m_dialog->wordList().begin(); it != end; ++it)
    {
        int twl = 0;
        int british = 0;
        int playability = 0;
        QString alphagram(QuackleIO::DictFactory::querier()->alphagram((*it).word));

        for (Dict::WordList::Iterator word = map[alphagram].begin(); word != map[alphagram].end(); ++word)
        {
            if ((*word).british)
                british++;
            else
                twl++;

            playability += (*word).playability;
        }

        if ((twl == numTwlAnagrams) && (british == numOswOnlyAnagrams))
            filteredList.append(*it);
    }

    m_dialog->setWordList(filteredList);
}
예제 #2
2
Dict::WordList QuackleIO::DictImplementation::query(const QString &query, int flags)
{
	QString modifiedQuery = query;
	modifiedQuery.replace(".", "?");

	int anagramFlags = Quackle::Generator::ClearBlanknesses;

	if (flags & Dict::Querier::NoRequireAllLetters)
		anagramFlags |= Quackle::Generator::NoRequireAllLetters;

	QRegExp wildcardRegexp("[\\*/]");
	if (wildcardRegexp.indexIn(modifiedQuery) >= 0)
	{
		if (!(flags & Dict::Querier::NoRequireAllLetters))
			anagramFlags |= Quackle::Generator::AddAnyLetters;

		modifiedQuery.replace(wildcardRegexp, QString());
	}

	vector<Quackle::LetterString> words(m_generator.anagramLetters(QuackleIO::Util::encode(modifiedQuery), anagramFlags));
	Dict::WordList ret;

	vector<Quackle::LetterString>::const_iterator end = words.end();
	for (vector<Quackle::LetterString>::const_iterator it = words.begin(); it != end; ++it)
	{
		Dict::Word dictWord;
		dictWord.word = QuackleIO::Util::letterStringToQString(*it);
		dictWord.wordLetterString = (*it);
		m_generator.storeWordInfo(&dictWord);

		if (flags & WithExtensions)
			m_generator.storeExtensions(&dictWord);

		ret.push_back(dictWord);
	}

	if (flags & NoRequireAllLetters)
	{
		ret.setSortBy(Dict::WordList::LengthLongestFirst);
	}
	else
	{
		ret.setSortBy(Dict::WordList::Alphabetical);
	}

	qSort(ret);

	return ret;
}
예제 #3
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));
}
예제 #4
0
파일: lister.cpp 프로젝트: liesen/quackle
void KeepBritishFilter::apply()
{
    Dict::WordList filteredList;
    const Dict::WordList &list = m_dialog->wordList();;
    Dict::WordList::ConstIterator end = list.end();

    for (Dict::WordList::ConstIterator it = list.begin(); it != end; ++it)
        if ((*it).british)
            filteredList.append(*it);

    m_dialog->setWordList(filteredList);
}
예제 #5
0
파일: lister.cpp 프로젝트: liesen/quackle
void RegexFilter::apply()
{
    QRegExp regexp(m_lineEdit->text());
    regexp.setCaseSensitivity(Qt::CaseInsensitive);

    Dict::WordList filteredList;
    const Dict::WordList &list = m_dialog->wordList();;
    Dict::WordList::ConstIterator end = list.end();

    for (Dict::WordList::ConstIterator it = list.begin(); it != end; ++it)
        if (regexp.indexIn((*it).word) >= 0)
            filteredList.append(*it);

    m_dialog->setWordList(filteredList);
}
예제 #6
0
파일: lister.cpp 프로젝트: liesen/quackle
void ListerDialog::setRemoveSowpods(bool removeSowpods)
{
    if (!removeSowpods)
        return;

    Dict::WordList filteredWords;

    Dict::WordList::Iterator end = m_wordList.end();
    for (Dict::WordList::Iterator it = m_wordList.begin(); it != end; ++it)
    {
        if (!(*it).british)
            filteredWords.append((*it));
    }

    m_wordList = filteredWords;
    populateListBox();
}
예제 #7
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));	
	}
}
예제 #8
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;
}
예제 #9
0
파일: lister.cpp 프로젝트: liesen/quackle
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);
}