implement stand-alone getSimilarityScore() with StringSimilarityMatcher()
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Fri, 7 Sep 2012 17:11:31 +0000 (19:11 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 20 Sep 2012 12:35:11 +0000 (14:35 +0200)
now that the instantiation is cheap, we can do that.

Change-Id: Ifd2c3155aa976ec634d4ed96ae796a60584ca9a4
Reviewed-by: hjk <qthjk@ovi.com>
src/linguist/shared/simtexth.cpp
src/linguist/shared/simtexth.h

index 902d776..c434043 100644 (file)
@@ -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)
 {
index 7cfe00a..0e20fa6 100644 (file)
@@ -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,