Mercurial > hg > classical
changeset 14:06b2ea2ca577 classical-rdf
* use floating-point scores for name matching
author | Chris Cannam |
---|---|
date | Fri, 19 Feb 2010 12:41:23 +0000 |
parents | a1d67e136c30 |
children | 701702f8959a |
files | common/Objects.cpp common/Objects.h testapp/Loader.cpp |
diffstat | 3 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/common/Objects.cpp Fri Feb 19 11:41:57 2010 +0000 +++ b/common/Objects.cpp Fri Feb 19 12:41:23 2010 +0000 @@ -275,7 +275,7 @@ return false; } -int +float Composer::matchFuzzyName(QString n) const { int fameBonus = m_pages.size(); @@ -284,9 +284,11 @@ return matchFuzzyName(n.toLower().split(sre, QString::SkipEmptyParts)); } -int +float Composer::matchFuzzyName(QStringList elements) const { + if (elements.empty()) return 0; + cacheNames(); int fameBonus = m_pages.size(); @@ -391,7 +393,7 @@ score += fameBonus; } // if (score > 1) std::cerr << "[score " << score << " for " << name().toStdString() << "]" << std::endl; - return score; + return float(score) / (elements.size() * 10); } static int
--- a/common/Objects.h Fri Feb 19 11:41:57 2010 +0000 +++ b/common/Objects.h Fri Feb 19 12:41:23 2010 +0000 @@ -357,7 +357,7 @@ * that the intended composer was this one. Higher return values * indicate greater confidence. */ - int matchFuzzyName(QString name) const; + float matchFuzzyName(QString name) const; /** * Given another name which is believed to be a user-entered @@ -367,7 +367,7 @@ * indicate greater confidence. The supplied name should have * been lower-cased and split on non-alphabetical characters. */ - int matchFuzzyName(QStringList name) const; + float matchFuzzyName(QStringList name) const; /** * Return the supplied name reduced into a "simplified" form,
--- a/testapp/Loader.cpp Fri Feb 19 11:41:57 2010 +0000 +++ b/testapp/Loader.cpp Fri Feb 19 12:41:23 2010 +0000 @@ -94,21 +94,21 @@ } */ while (!std::cin.eof()) { - std::cerr << "Enter composer name: "; + std::cerr << std::endl << "Enter composer name: "; std::string s; getline(std::cin, s); - QMultiMap<int, QString> matches; + QMultiMap<float, QString> matches; QRegExp sre("[\\., -]+"); QStringList elements = QString::fromStdString(s) .toLower().split(sre, QString::SkipEmptyParts); foreach (QObject *o, composers) { Composer *c = qobject_cast<Composer *>(o); if (!c) continue; - int value = c->matchFuzzyName(elements); + float value = c->matchFuzzyName(elements); matches.insert(value, c->getSortName(false)); } int n = 0; - for (QMultiMap<int, QString>::const_iterator i = matches.end(); + for (QMultiMap<float, QString>::const_iterator i = matches.end(); i != matches.begin(); ) { --i; if (i.key() < 0) continue; @@ -119,7 +119,9 @@ } else { std::cerr << " - "; } - std::cerr << i.value().toStdString() << std::endl; + std::cerr << i.value().toStdString(); + for (int c = i.value().length(); c < 40; ++c) std::cerr << " "; + std::cerr << "[" << i.key() << "]" << std::endl; if (++n > 5 || i.key() < 1) break; } if (n == 0) std::cerr << "No matches" << std::endl;