-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
82 lines (72 loc) · 2.54 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// main.cpp
#include "PersonProfile.h"
#include "AttributeTranslator.h"
#include "MemberDatabase.h"
#include "MatchMaker.h"
#include "provided.h"
#include <iostream>
#include <string>
#include <vector>
const std::string MEMBERS_FILE = "/home/modani/GitHub/Unhinged/members.txt";
const std::string TRANSLATOR_FILE = "/home/modani/GitHub/Unhinged/translator.txt";
bool findMatches(const MemberDatabase& mdb, const AttributeTranslator& at);
int main() {
MemberDatabase mdb;
if (!mdb.LoadDatabase(MEMBERS_FILE))
{
std::cout << "Error loading " << MEMBERS_FILE << std::endl;
return 1;
}
AttributeTranslator at;
if (!at.Load(TRANSLATOR_FILE))
{
std::cout << "Error loading " << TRANSLATOR_FILE << std::endl;
return 1;
}
while (findMatches(mdb, at))
;
std::cout << "Happy dating!" << std::endl;
}
bool findMatches(const MemberDatabase& mdb, const AttributeTranslator& at)
{
// Prompt for email
std::string email;
const PersonProfile* pp;
for (;;) {
std::cout << "Enter the member's email for whom you want to find matches: ";
std::getline(std::cin, email);
if (email.empty())
return false;
pp = mdb.GetMemberByEmail(email);
if (pp != nullptr)
break;
std::cout << "That email is not in the member database." << std::endl;
}
// Show member's attribute-value pairs
std::cout << "The member has the following attributes:" << std::endl;
for (int k = 0; k != pp->GetNumAttValPairs(); k++) {
AttValPair av;
pp->GetAttVal(k, av);
std::cout << av.attribute << " --> " << av.value << std::endl;
}
// Prompt user for threshold
int threshold;
std::cout << "How many shared attributes must matches have? ";
std::cin >> threshold;
std::cin.ignore(10000, '\n');
// Print matches and the number of matching translated attributes
MatchMaker mm(mdb, at);
std::vector<EmailCount> emails = mm.IdentifyRankedMatches(email, threshold);
if (emails.empty())
std::cout << "No member was a good enough match." << std::endl;
else {
std::cout << "The following members were good matches:" << std::endl;;
for (const auto& emailCount : emails) {
const PersonProfile* pp = mdb.GetMemberByEmail(emailCount.email);
std::cout << pp->GetName() << " at " << emailCount.email << " with "
<< emailCount.count << " matches!" << std::endl;
}
}
std::cout << std::endl;
return true;
}