Mercurial > hg > classical
view common/Matcher.cpp @ 30:8bed05455706
* Make classical code build
author | Chris Cannam |
---|---|
date | Tue, 16 Mar 2010 17:36:28 +0000 |
parents | 7d8a6167febb |
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; } }