0 votes
1 view
in RPA by (5.3k points)

I have a question regarding partial match of two strings.

I have a string and I need to validate it. To be more specific, I have an output from OCR reading and it contains some mistakes, of course. I need to check if the string is really there but as it can be written incorrectly I need only 70% match.

Is it possible to do that in UiPath? The string is in notepad (.txt) so any idead would be helpful.

1 Answer

0 votes
by (9.5k points)

you can do by passing OCR output/words_detected against a base word.(double fuzzyness is 0-1)

list<string> Search(string word, list<string> wordList, double fuzzyness) { list<string> foundWords; for (string s : wordList) { int levenshteinDistance = LevenshteinDistance(word, s); int length = max(word.length(), s.length()); double score = 1.0 - (double)levenshteinDistance / length; if (score > fuzzyness) foundWords.push_back(s); } if (foundWords.size() > 1) { for (double d = fuzzyness; ; d++) { foundWords = Search(word, wordList, d); if (foundWords.size() == 1) break; } } return foundWords;} int LevenshteinDistance(string src, string dest) { std::vector<vector<int>> d; d.resize((int)src.size() + 1, std::vector<int>((int)dest.size() + 1, 0)); int i, j, cost; std::vector<char> str1(src.begin(), src.end()); std::vector<char> str2(dest.begin(), dest.end()); for (i = 0; i <= str1.size(); i++) d[i][0] = i; for (j = 0; j <= str2.size(); j++) d[0][j] = j; for (i = 1; i <= str1.size(); i++) { for (j = 1; j <= str2.size(); j++) { if (str1[i - 1] == str2[j - 1]) cost = 0; else cost = 1; d[i][j] = min(d[i - 1][j] + 1, min(d[i][j - 1] + 1, d[i - 1][j - 1] + cost)); if ((i > 1) && (j > 1) && (str1[i - 1] == str2[j - 2]) && (str1[i - 2] == str2[j - 1])) d[i][j] = min(d[i][j], d[i - 2][j - 2] + cost); } } return d[str1.size()][str2.size()];}

Related questions

0 votes
1 answer
asked Jul 13, 2019 in RPA by Abhishek_31 (12.8k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 10, 2019 in RPA by Abhishek_31 (12.8k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...