-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphSchema.cpp
More file actions
83 lines (64 loc) · 2.04 KB
/
GraphSchema.cpp
File metadata and controls
83 lines (64 loc) · 2.04 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
81
82
83
#include "GraphSchema.h"
GraphSchema::GraphSchema(string file) {
gIO = new GraphIO(file, false, false);
vector<int> params;
gIO->mapping(this, 0, params);
delete gIO;
gIO = new GraphIO(file, true, false);
}
GraphSchema::GraphSchema(string file, string base_dir, unordered_map<string, GraphSchema*>& schemas, bool& succ) {
gIO = new GraphIO(file, false, false);
vector<int> params;
gIO->mapping(this, 0, params);
delete gIO;
if (schemas.find(name) != schemas.end()) {
succ = false;
return;
}
else {
succ = true;
}
gIO = new GraphIO(base_dir + "\\" + name + ".sch", true, false);
}
GraphSchema::GraphSchema(string file, string schemaname, unordered_map<string, vector<pair<string, string>>>& nodeAttrMap, unordered_map<string, vector<pair<string, string>>>& edgeAttrMap, unordered_map<string, vector<pair<string, string>>>& schemaNetwork) {
gIO = new GraphIO(file, true, false);
name = schemaname;
nodenum = nodeAttrMap.size();
edgelabelnum = edgeAttrMap.size();
network = vector<unordered_map<int, vector<int>>>(nodenum + 1);
nodenamemap["ANY"] = 0;
int index = 0;
for (auto& nl : nodeAttrMap) {
nodelabels.push_back(nl.first);
nodenamemap[nl.first] = index + 1;
for (int j = 0; j < nl.second.size(); ++j) {
nodelabeltoattr[index + 1].push_back(make_pair(nl.second[j].first, returnTypeCode(nl.second[j].second)));
}
index++;
}
index = 0;
for (auto& el : edgeAttrMap) {
edgelabels.push_back(el.first);
edgenamemap[el.first] = index + 1;
for (int j = 0; j < el.second.size(); ++j) {
edgelabeltoattr[index + 1].push_back(make_pair(el.second[j].first, returnTypeCode(el.second[j].second)));
}
index++;
}
edgenum = 0;
for (const auto& rel : schemaNetwork) {
for (const auto& reledge : rel.second) {
int srcint = nodenamemap[reledge.first];
int dstint = nodenamemap[reledge.second];
int relint = edgenamemap[rel.first];
network[srcint][dstint].push_back(relint);
edgenum++;
}
}
}
GraphSchema::~GraphSchema() {
vector<int> params;
gIO->unmapping(this, 0, params);
if (gIO)
delete gIO;
}