Mercurial > hg > classical
view common/Matcher.cpp @ 31:07efb25d24d6
* Merge revs 7200-7222 from SVN (update use of loader API, switch to using
mapper for merge operation)
author | Chris Cannam |
---|---|
date | Thu, 18 Mar 2010 16:59:24 +0000 |
parents | 8bed05455706 |
children | 84d6acb6b3ba |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ #include "Matcher.h" #include "Objects.h" #include <QMultiMap> using namespace Dataquay; namespace ClassicalData { ComposerTypingQuickMatcher::ComposerTypingQuickMatcher(QList<Composer *> cl) { foreach (Composer *c, cl) { m_composers[c->property("uri").value<Uri>()] = c; } } GuessList ComposerTypingQuickMatcher::match(QString text, int maxResults) const { GuessList results; QMap<Guess, int> matches; foreach (Composer *c, m_composers) { float value = c->matchTypingQuick(text); if (value <= 0) continue; matches.insert(Guess(value, c), 1); } int n = 0; for (QMap<Guess, int>::const_iterator i = matches.begin(); i != matches.end(); ++i) { results.push_back(i.key()); if (++n > maxResults) break; } return results; } ComposerTypingThoroughMatcher::ComposerTypingThoroughMatcher(QList<Composer *> cl) { foreach (Composer *c, cl) { m_composers[c->property("uri").value<Uri>()] = c; } } GuessList ComposerTypingThoroughMatcher::match(QString text, int maxResults) const { GuessList results; QMap<Guess, int> matches; foreach (Composer *c, m_composers) { float value = c->matchTyping(text); if (value <= 0) continue; matches.insert(Guess(value, c), 1); } int n = 0; for (QMap<Guess, int>::const_iterator i = matches.begin(); i != matches.end(); ++i) { results.push_back(i.key()); if (++n > maxResults) break; } return results; } }