/* ------------------------------------------------------------------------------------*/
/* * Document Distance Problem
This problem calculates percentage similarity between two files.
* Language used- C++
* Function Used-
* map createMap(string location)-- convert a ginven file to map whose
first attribute is the word and second attribute is the frequency of that word in
the file
* void printMap(map mapDoc)-- printing map
* int countTotalWords(map mapDoc)-- calculate total no. of words in the
file.
*/
/*-------------------------------------------------------------------------------------------*/
#include
using namespace std;
map createMap(string location){
ifstream in_file1(location);
string line,doc;
map mapDoc;
if (in_file1.is_open()) {
while ( getline (in_file1, line) ) {
for(int i{0};isecond++;
}else
{
mapDoc.insert(make_pair(doc,1));
}
doc="";
}
}
}
in_file1.close();
}
else
cout<<"wrongggg";
return mapDoc;
}
void printMap(map mapDoc){
cout<<"----------------------------------------------------"<first<second< mapDoc){
long long size{0};
for(auto it=mapDoc.begin();it!=mapDoc.end();it++)
size+=it->second;
return size;
}
int main(){
string line,doc1,doc2;
long long int mul{0},size1,size2;
double dotProduct;
map mapDoc1;
map mapDoc2;
mapDoc1=createMap("files/a.txt");
mapDoc2=createMap("files/b.txt");
printMap(mapDoc1);
printMap(mapDoc2);
for(auto it=mapDoc1.begin();it!=mapDoc1.end();it++){
auto temp=mapDoc2.find(it->first);
if(temp!=mapDoc2.end()){
mul+=(temp->second)+(it->second);
cout<first<<" "<first<<" "<