-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspell_check.cpp
More file actions
54 lines (51 loc) · 1.23 KB
/
spell_check.cpp
File metadata and controls
54 lines (51 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<bits/stdc++.h>
#include "soundex.h"
#include "edit.h"
using namespace std;
multimap <string, string> model;
void create_map_model(){
fstream file;
string word,tmp;
string filename="words_alpha.txt";
file.open(filename.c_str());
while(file>>word){
tmp=soundex(word);
model.insert(pair <string, string> (tmp,word));
}
file.close();
}
int main(){
create_map_model();
multimap<string, string> :: iterator itr;
multimap<int, string> :: iterator itr2;
multimap <string, string> near_words;
multimap <int, string> final;
string a,b;
int sum=0;
//cout<<"Enter string:";
cin>>a;
b=soundex(a);
for(itr=model.begin(); itr!=model.end(); itr++){
if(b==itr->first)
near_words.insert(pair<string, string> (itr->first, itr->second));
}
for(itr=near_words.begin(); itr!=near_words.end();itr++){
if(edit(a,a.length(),itr->second,itr->second.length())<3){
if(edit(a,a.length(),itr->second,itr->second.length())==0){
cout<<"Word is valid ";
return 0;
}
final.insert(pair<int, string> (edit(a,a.length(),itr->second,itr->second.length()), itr->second));
sum++;
}
}
if( sum!=0){
for(itr2=final.begin(); itr2!=final.end();itr2++){
cout<<itr2->second<<",";
}
}
else{
cout<<"No Suggestions ";
}
return 0;
}