-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttributeTranslator.cpp
63 lines (54 loc) · 1.41 KB
/
AttributeTranslator.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
//
// AttributeTranslator.cpp
// CS32_4
//
// Created by Snigdha Kansal on 3/8/22.
//
#include "AttributeTranslator.h"
using namespace std;
bool AttributeTranslator::Load(string filename)
{
ifstream infile(filename);
if (!infile)
{
return false;
}
while (infile)
{
string line;
getline(infile, line);
if (line == "")
{
break;
}
istringstream iss(line);
string s_att, s_val, c_att, c_val;
getline(iss, s_att, ',');
getline(iss, s_val, ',');
getline(iss, c_att, ',');
getline(iss, c_val, '\n');
string s_attval = s_att + s_val;
AttValPair c_attval(c_att, c_val);
vector<AttValPair> *compatible_pairs = m_radixtree.search(s_attval);
if (compatible_pairs == nullptr)
{
vector<AttValPair> new_compatible_pairs = {c_attval};
m_radixtree.insert(s_attval, new_compatible_pairs);
}
else
{
compatible_pairs->push_back(c_attval);
}
}
return true;
}
vector<AttValPair> AttributeTranslator::FindCompatibleAttValPairs(const AttValPair &source) const
{
string s_attval = source.attribute + source.value;
vector<AttValPair> *compatible_pairs = m_radixtree.search(s_attval);
if (compatible_pairs == nullptr)
{
return vector<AttValPair>();
}
return *compatible_pairs;
}