summaryrefslogtreecommitdiff
path: root/DSACore/Auxiliary/SpellCorrect.cs
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-05-19 16:03:38 +0200
committerDennis Kobert <d-kobert@web.de>2019-05-19 16:03:38 +0200
commitf89f308c525e9deebc6d2cf6416e27dfe1a299dc (patch)
tree7097ef871ead0245efda696198443eab8e443d3a /DSACore/Auxiliary/SpellCorrect.cs
parentf3983341be939235c1a6cd522b3bb5cc318a6d1a (diff)
Cleanup DiscoBot Project
Diffstat (limited to 'DSACore/Auxiliary/SpellCorrect.cs')
-rw-r--r--DSACore/Auxiliary/SpellCorrect.cs103
1 files changed, 31 insertions, 72 deletions
diff --git a/DSACore/Auxiliary/SpellCorrect.cs b/DSACore/Auxiliary/SpellCorrect.cs
index c9603f6..3ef7bb6 100644
--- a/DSACore/Auxiliary/SpellCorrect.cs
+++ b/DSACore/Auxiliary/SpellCorrect.cs
@@ -15,44 +15,25 @@
public static int CompareEasy(string x, string y)
{
- if (string.IsNullOrEmpty(x))
- {
- throw new ArgumentException("message", nameof(x));
- }
+ if (string.IsNullOrEmpty(x)) throw new ArgumentException("message", nameof(x));
- if (string.IsNullOrEmpty(y))
- {
- throw new ArgumentException("message", nameof(y));
- }
+ if (string.IsNullOrEmpty(y)) throw new ArgumentException("message", nameof(y));
- if (x.Equals(y))
- {
- return 0;
- }
+ if (x.Equals(y)) return 0;
x = x.ToLower();
y = y.ToLower();
- if (x.Equals(y))
- {
- return 1;
- }
+ if (x.Equals(y)) return 1;
var subs = y.Split(' ', '/');
- int score = subs.Count();
- foreach (string s in subs)
- {
+ var score = subs.Count();
+ foreach (var s in subs)
if (s.Equals(x))
- {
score--;
- }
- }
- if (score < subs.Count())
- {
- return score + 1;
- }
+ if (score < subs.Count()) return score + 1;
- return 100000 - (int)(CompareExact(x, y) * 1000.0);
+ return 100000 - (int) (CompareExact(x, y) * 1000.0);
/*if (y.Contains(x))
return 6;*/
}
@@ -70,7 +51,6 @@
public static double CompareExact(string s, string q)
{
-
s = s.ToLower();
q = q.ToLower();
@@ -81,67 +61,46 @@
double decay;
- double[,] matrix = new double[s.Length + 1, q.Length + 1];
- double max = 0.0;
+ var matrix = new double[s.Length + 1, q.Length + 1];
+ var max = 0.0;
matrix[0, 0] = 0.0;
-
+
for (i = 1; i < s.Length; i++)
- {
- // matrix[i, 0] = 0.0;
+ // matrix[i, 0] = 0.0;
matrix[i, 0] = i * Gap;
- }
- for (i = 1; i < q.Length; i++)
- {
- matrix[0, i] = 0.0;
- }
+ for (i = 1; i < q.Length; i++) matrix[0, i] = 0.0;
for (i = 1; i <= s.Length; i++)
+ for (j = 1; j <= q.Length; j++)
{
- for (j = 1; j <= q.Length; j++)
- {
- decay = j / (double)(s.Length * 1000);
- double add = s[i - 1] == q[j - 1] ? (Match - decay) : Mismatch;
- double score = matrix[i - 1, j - 1] + add;
+ decay = j / (double) (s.Length * 1000);
+ var add = s[i - 1] == q[j - 1] ? Match - decay : Mismatch;
+ var score = matrix[i - 1, j - 1] + add;
- if (score < (matrix[i - 1, j] + Gap))
- {
- score = matrix[i - 1, j] + Gap;
- }
+ if (score < matrix[i - 1, j] + Gap) score = matrix[i - 1, j] + Gap;
- if (score < (matrix[i, j - 1] + Gap))
- {
- score = matrix[i, j - 1] + Gap;
- }
+ if (score < matrix[i, j - 1] + Gap) score = matrix[i, j - 1] + Gap;
- if (i > 1 && j > 1)
+ if (i > 1 && j > 1)
+ if (s[i - 1] == q[j - 2] && s[i - 2] == q[j - 1])
{
- if (s[i - 1] == q[j - 2] && s[i - 2] == q[j - 1])
- {
- add = (3 / 2.0) * Match - decay;
- if (score < matrix[i - 2, j - 2] + add)
- {
- score = matrix[i - 2, j - 2] + add;
- }
- }
+ add = 3 / 2.0 * Match - decay;
+ if (score < matrix[i - 2, j - 2] + add) score = matrix[i - 2, j - 2] + add;
}
-
- // if (score < 0)
- // {
- // score = 0;
- // }
- if (max < score && i == s.Length)
- {
- max = score;
- }
+ // if (score < 0)
+ // {
+ // score = 0;
+ // }
+
+ if (max < score && i == s.Length) max = score;
- matrix[i, j] = score;
- }
+ matrix[i, j] = score;
}
return max;
}
}
-}
+} \ No newline at end of file