This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJsim.cpp
63 lines (56 loc) · 1.68 KB
/
Jsim.cpp
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
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
#include"characteristic_matrix.h"
using namespace std;
int k = 5;
int ndocs = 2;
vector<vector <bool> > CM;
vector<vector<char> > docs;
void iniParams(){
//Inicialitzar el Parametres
cout << "Que K vols utilitzar? (0: usar K per defecte = " << k <<")" << endl;
int aux;
cin >> aux;
if (aux>0) k=aux;
}
void readDocuments(char* argv[]) {
//Llegir el dos documents
ifstream fileReader;
string out;//aproximation
for (int index=1; index<=ndocs; index++) {
const char *filename = argv[index];
fileReader.open(filename);
vector<char> document;
while (!fileReader.eof()) {
fileReader >> out;
for (int i = 0; i < out.size(); i++) document.push_back(out[i]);
document.push_back(' '); //in case we must include ' ' as shingle.
}
docs.push_back(document);
fileReader.close();
}
}
void writeSimilarity() {
//Escriu per pantalla la Similitud de Jaccard a partir de la Matriu Caracteristica
double x = 0.0;
double y = 0.0;
for (int i = 0; i < CM.size(); i++) {
int aux = 0;
if (CM[i][0]) aux++;
if (CM[i][1]) aux++;
if (aux == 2) x++;
if (aux == 1) y++;
}
double jSim = x/(x+y);
cout << "Similitud de Jaccard per els dos documents = " << jSim << endl;
}
int main(int argc, char *argv[]) {
if (argc != 3){ cout << "Usage: parámetros deben ser 2 nombres de archivos de texto del mismo directorio a comparar" << endl; return 0;}
iniParams();
readDocuments(argv);
Characteristic_Matrix cm(k,docs);
CM = cm.getCM();
writeSimilarity();
}