Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- #include <string>
- int levenshtein(string const a, string const b) {
- int lengthA = a.length(), lengthB = b.length;
- int d[lengthA + 1][lengthB + 1];
- for (int i = 0; i <= lengthA; i++)
- for (int j = 0; j <= lengthB; j++)
- d[i][j] = -1;
- int dist(int i, int j) {
- if (d[i][j] >= 0) return d[i][j];
- int x;
- if (i == lengthA)
- x = lengthB - j;
- else if (j == lengthB)
- x = lengthA - i;
- else if (s[i] == t[j])
- x = dist(i + 1, j + 1);
- else {
- x = dist(i + 1, j + 1);
- int y;
- if ((y = dist(i, j + 1)) < x) x = y;
- if ((y = dist(i + 1, j)) < x) x = y;
- x++;
- }
- return d[i][j] = x;
- }
- return dist(0, 0);
- }
- int main()
- {
- using namespace std;
- int stop = 0;
- ifstream dictionary;
- dictionary.open ("wrt.dic");
- ifstream text;
- text.open ("ocr_output.txt");
- string buffer;
- string wordFromDict;
- dictionary.Replace("\n", "\r\n");
- while (text >> buffer)
- {
- if (buffer.length() > 1){
- cout<< buffer << '\n';
- while (dictionary >> wordFromDict) {
- if (wordFromDict == buffer) {
- stop = 1;
- }
- }
- }
- }
- if(text.eof()){
- cout << "End of file \n";
- }
- text.close();
- dictionary.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement