From 79a9dab4fa751a60d046eb83d11a0954bd91f3f9 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 7 Sep 2012 19:11:31 +0200 Subject: [PATCH] implement stand-alone getSimilarityScore() with StringSimilarityMatcher() now that the instantiation is cheap, we can do that. Change-Id: Ifd2c3155aa976ec634d4ed96ae796a60584ca9a4 Reviewed-by: hjk --- src/linguist/shared/simtexth.cpp | 19 ------------------- src/linguist/shared/simtexth.h | 12 +++++++++++- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/linguist/shared/simtexth.cpp b/src/linguist/shared/simtexth.cpp index 902d776..c434043 100644 --- a/src/linguist/shared/simtexth.cpp +++ b/src/linguist/shared/simtexth.cpp @@ -196,25 +196,6 @@ int StringSimilarityMatcher::getSimilarityScore(const QString &strCandidate) return score; } -/** - * Checks how similar two strings are. - * The return value is the score, and a higher score is more similar - * than one with a low score. - * Linguist considers a score over 190 to be a good match. - * \sa StringSimilarityMatcher - */ -int getSimilarityScore(const QString &str1, const QString &str2) -{ - CoMatrix cmTarget(str2); - CoMatrix cm(str1); - int delta = qAbs(str1.size() - str2.size()); - - int score = ( (worth(intersection(cm, cmTarget)) + 1) << 10 ) - / ( worth(reunion(cm, cmTarget)) + (delta << 1) + 1 ); - - return score; -} - CandidateList similarTextHeuristicCandidates(const Translator *tor, const QString &text, int maxCandidates) { diff --git a/src/linguist/shared/simtexth.h b/src/linguist/shared/simtexth.h index 7cfe00a..0e20fa6 100644 --- a/src/linguist/shared/simtexth.h +++ b/src/linguist/shared/simtexth.h @@ -102,7 +102,17 @@ private: int m_length; }; -int getSimilarityScore(const QString &str1, const QString &str2); +/** + * Checks how similar two strings are. + * The return value is the score, and a higher score is more similar + * than one with a low score. + * Linguist considers a score over 190 to be a good match. + * \sa StringSimilarityMatcher + */ +static inline int getSimilarityScore(const QString &str1, const QString &str2) +{ + return StringSimilarityMatcher(str1).getSimilarityScore(str2); +} CandidateList similarTextHeuristicCandidates( const Translator *tor, const QString &text, -- 2.7.4