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; }
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); }