public void TestScoringEmptyString() { var scorerType = typeof(IRatioScorer); var scorerTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where(p => scorerType.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract); MethodInfo getScorerCacheMethodInfo = typeof(ScorerCache).GetMethod("Get"); string nullString = null; //Null doesnt seem to be handled by any scorer string emptyString = ""; string whitespaceString = " "; string[] nullOrWhitespaceStrings = { emptyString, whitespaceString }; foreach (Type t in scorerTypes) { System.Diagnostics.Debug.WriteLine($"Testing {t.Name}"); MethodInfo m = getScorerCacheMethodInfo.MakeGenericMethod(t); IRatioScorer scorer = m.Invoke(this, new object[] { }) as IRatioScorer; foreach (string s in nullOrWhitespaceStrings) { System.Diagnostics.Debug.WriteLine($"Testing string '{s}'"); try { scorer.Score(s, "TEST"); } catch (InvalidOperationException e) { Assert.Fail($"{t.Name}.score failed with empty string as first parameter"); } try { scorer.Score("TEST", s); } catch (InvalidOperationException e) { Assert.Fail($"{t.Name}.score failed with empty string as second parameter"); } try { scorer.Score(s, s); } catch (InvalidOperationException e) { Assert.Fail($"{t.Name}.score failed with empty string as both parameters"); } } } }
public static IEnumerable <ExtractedResult <T> > ExtractWithoutOrder <T>(T query, IEnumerable <T> choices, Func <T, string> processor, IRatioScorer scorer, int cutoff = 0) { int index = 0; var processedQuery = processor(query); foreach (var choice in choices) { double score = scorer.Score(processedQuery, processor(choice)); if (score >= cutoff) { yield return(new ExtractedResult <T>(choice, score, index)); } index++; } }
public void TokenSetScorer_SameInput_Returns100(string s1, string s2) { Assert.That(_scorer.Score(s1, s2), Is.EqualTo(100)); Assert.That(_partialScorer.Score(s1, s2), Is.EqualTo(100)); }