Repository navigation
Expand file tree
/
Copy pathMatchMaker.cpp
More file actions
80 lines (70 loc) · 2.3 KB
/
Copy pathMatchMaker.cpp
File metadata and controls
80 lines (70 loc) · 2.3 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
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
//
// MatchMaker.cpp
// proj4
//
// Created by Andy on 3/3/22.
//
#include "MatchMaker.h"
#include "MemberDatabase.h"
#include "AttributeTranslator.h"
#include "PersonProfile.h"
#include "utility.h"
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
MatchMaker::MatchMaker(const MemberDatabase& mdb, const AttributeTranslator& at)
{
database = &mdb;
translator = &at;
}
std::vector<EmailCount> MatchMaker::IdentifyRankedMatches(std::string email, int threshold) const
{
const PersonProfile* person = database->GetMemberByEmail(email);
std::set<AttValPair> totalPairs;//set so no duplicates
for(int i = 0;i<person->GetNumAttValPairs();i++)//gets all compatible pairs for that person
{
AttValPair attval;
person->GetAttVal(i, attval);
std::vector<AttValPair> compatiblePairs = translator->FindCompatibleAttValPairs(attval);
for(int k = 0;k<compatiblePairs.size();k++)
{
//std::cout << compatiblePairs[k].attribute << "," << compatiblePairs[k].value << std::endl;
totalPairs.insert(compatiblePairs[k]);
}
}
std::map<std::string, int> emailToCount;
std::map<std::string, int>:: iterator mapit;
std::set<AttValPair>::iterator it;
it = totalPairs.begin();
while(it!=totalPairs.end())//gets map with all emails and number of matches
{
std::vector<std::string> matchingMembers = database->FindMatchingMembers(*it);
for(int i = 0;i<matchingMembers.size();i++)
{
mapit = emailToCount.find(matchingMembers[i]);
if(mapit!=emailToCount.end())
{
mapit->second += 1;
}
else
{
emailToCount.insert({matchingMembers[i], 1});
}
}
it++;
}
std::vector<EmailCount> compatiblePeople;
mapit = emailToCount.begin();
while(mapit!=emailToCount.end())//creates the emailCount vector
{
if(mapit->second>=threshold && mapit->first != email)
{
EmailCount newPerson = EmailCount(mapit->first, mapit->second);
compatiblePeople.push_back(newPerson);
}
mapit++;
}
std::sort(compatiblePeople.begin(), compatiblePeople.end());
return compatiblePeople;
}