Mercurial > hg > classical
view common/Matcher.cpp @ 33:84d6acb6b3ba
* Bit more work on track composer identification
author | Chris Cannam |
---|---|
date | Mon, 22 Mar 2010 16:41:01 +0000 |
parents | 8bed05455706 |
children | 271cbaf6e8d9 |
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) : m_composers(cl) { } GuessList ComposerTypingQuickMatcher::match(QString text, int maxResults, float threshold) const { GuessList results; QMap<Guess, int> matches; foreach (Composer *c, m_composers) { float value = c->matchTypingQuick(text); if (value < threshold) 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) : m_composers(cl) { } GuessList ComposerTypingThoroughMatcher::match(QString text, int maxResults, float threshold) const { GuessList results; QMap<Guess, int> matches; foreach (Composer *c, m_composers) { float value = c->matchTyping(text); if (value < threshold) 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; } ComposerFullTextMatcher::ComposerFullTextMatcher(QList<Composer *> cl) : m_composers(cl) { } GuessList ComposerFullTextMatcher::match(QString text, int maxResults, float threshold) const { GuessList results; QMap<Guess, int> matches; foreach (Composer *c, m_composers) { float value = c->matchFuzzyName(text); if (value < threshold) 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; } }