// compares two semantic strings // returns the score of the semantic match public float Match(SemanticString other) { this.other = other; this.tokenMatchPoints = new float[this.NumTokens(), other.NumTokens()]; string one; string two; float assocStrength; for (int i=0; i < this.NumTokens(); i++) { one = this.GetToken(i).ToLower(); for (int j = 0; j < other.NumTokens(); j++) { two = other.GetToken(j).ToLower(); // tokens are identical if (one.CompareTo(two) == 0) { this.tokenMatchPoints[i, j] = this.SAME; } // tokens are associated else if ((assocStrength = RecognizeAssociation(one, two)) > 0f) { this.tokenMatchPoints[i, j] = this.SAME * assocStrength; } // one token includes the other. points awarded are based on the percentage of the larger string that is matched else if (one.Length > 1 && one.Length < two.Length && one.CompareTo(two.Substring(0, one.Length)) == 0) { this.tokenMatchPoints[i, j] = ((float)one.Length / (float)two.Length) * this.SAME; } else if (two.Length > 1 && two.Length < one.Length && two.CompareTo(one.Substring(0, two.Length)) == 0) { this.tokenMatchPoints[i, j] = ((float)two.Length / (float)one.Length) * this.SAME; } } } return GetMatchScore(); }
void exerciseSemanticStrings() { SemanticString text = new SemanticString(); text.Tokenize("double delim"); text.DumpTokens(); text.Tokenize("single"); text.DumpTokens(); text.Tokenize("then the(fox)jumped-over.the_fence"); text.DumpTokens(); SemanticString text2 = new SemanticString(); text2.Tokenize("the fox is foxy"); Console.WriteLine("match score:"); Console.WriteLine(text.GetText()); Console.WriteLine(text2.GetText()); float matchScore = text.Match(text2); Console.WriteLine(matchScore); Console.WriteLine(text.ReplaceYearAndMaybeMonth("frank201409was here")); Console.WriteLine(text.ReplaceYearAndMaybeMonth("201409was here")); Console.WriteLine(text.ReplaceYearAndMaybeMonth("frank201409")); Console.WriteLine(text.ReplaceYearAndMaybeMonth("frank2014-09")); Console.WriteLine(text.ReplaceYearAndMaybeMonth("201409")); Console.WriteLine(text.ReplaceYearAndMaybeMonth("frank2014_09was here")); text.Tokenize("SHCN Provider File"); text2.Tokenize("Providers SHCN_Group__c"); Console.WriteLine("match score:"); Console.WriteLine(text.GetText()); Console.WriteLine(text2.GetText()); matchScore = text.Match(text2); Console.WriteLine(matchScore); }