-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.cpp
52 lines (46 loc) · 1.35 KB
/
App.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
#include <climits>
#include <string>
#include <unistd.h>
#include <iostream>
#include "App.h"
string get_enron_path() {
char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
if (len != -1) {
buff[len] = '\0';
string path(buff);
string undesired_part("/StringMatching/bin/Debug/StringMatching");
path = path.substr(0, path.size() - undesired_part.size());
return path.append("/maildir");
} else {
cout << "Error with program path";
return nullptr;
}
}
void update_min(pair<int, float>& min, const array<measure, NB_SCORES>& scores) {
min.second = scores[0].score;
min.first = 0;
for(int i = 1; i < scores.size(); i++) {
if (scores[i].score < min.second) {
min.second = scores[i].score;
min.first = i;
}
}
}
int intersection_of(const set<int> &setA, const set<int> &setB) {
int intersection = 0;
int nb_words_remaining = setA.size();
for (int A : setA) {
if (setB.find(A) != setB.end())
intersection++;
if ((float)( intersection + (--nb_words_remaining)) / setA.size() < THRESHOLD) {
return -1;
}
}
return intersection;
}
void measure::set(int id_A, int id_B, float new_score) {
mail_id_A = id_A;
mail_id_B = id_B;
score = new_score;
}