-
Notifications
You must be signed in to change notification settings - Fork 1
/
graph.cpp
104 lines (91 loc) · 2.98 KB
/
graph.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include"graph.h"
graph_::graph_(DBHelper *db, ConfigHelper *cf):
dbHelper(db), configHelper(cf)
{
}
//setnodecoordinate
void graph_::setnodecoordinate()
{
}
/*
* QList<node> nodelist;
* QList<edge> edgelist;
*/
void graph_::start()
{
dbHelper->getFileResults(frs);
for (int i = 0; i < frs.count(); i++)
{
node_ n;
n.setnode(i, frs[i].file.name, frs[i].relations, frs[i].file.path);
n.keywords = frs[i].keywords;
n.labels = frs[i].labels;
nodelist.append(n);
}
double edgePercent = (double)configHelper->getDisplayEdgePercent();
edgePercent /= 100;
for (int i = 0; i < nodelist.count(); i++)
{
for (int c = 0 ; c < nodelist[i].relations.count(); c++)
{
edge_ e;
for (int b = 0; b < nodelist.count(); b++)
{
double weight = nodelist[i].relations[c].keywordDegree * KEYWORD_RELATION_WEIGHT
+ nodelist[i].relations[c].labelDegree * LABEL_RELATION_WEIGHT
+ nodelist[i].relations[c].attributeDegree * ATTRIBUTE_RELATION_WEIGHT;
if (nodelist[i].relations[c].file.path == nodelist[b].path && weight >= edgePercent)
{
e.first = &nodelist[i];
e.second = &nodelist[b];
e.weight = weight;
edgelist.append(e);
}
}
}
}
}
void graph_::start(QString labelname)
{
dbHelper->getFileResults(frs);
QList<FileResult> frs_;
for (int i = 0 ; i < frs.count(); i++)
{
for (int j = 0 ; j < frs[i].labels.count(); j++)
{
qDebug() << frs[i].labels[j].name;
if (frs[i].labels[j].name == labelname)
frs_.append(frs[i]);
}
}
for (int i = 0; i < frs_.count(); i++)
{
node_ n;
n.setnode(i, frs_[i].file.name, frs_[i].relations, frs_[i].file.path);
n.keywords = frs_[i].keywords;
n.labels = frs[i].labels;
nodelist.append(n);
}
double edgePercent = (double)configHelper->getDisplayEdgePercent();
edgePercent /= 100;
for (int i = 0; i < nodelist.count(); i++)
{
for (int c = 0 ; c < nodelist[i].relations.count(); c++)
{
edge_ e;
for (int b = 0; b < nodelist.count(); b++)
{
double weight = nodelist[i].relations[c].keywordDegree * KEYWORD_RELATION_WEIGHT
+ nodelist[i].relations[c].labelDegree * LABEL_RELATION_WEIGHT
+ nodelist[i].relations[c].attributeDegree * ATTRIBUTE_RELATION_WEIGHT;
if (nodelist[i].relations[c].file.path == nodelist[b].path && weight >= edgePercent)
{
e.first = &nodelist[i];
e.second = &nodelist[b];
e.weight = weight;
edgelist.append(e);
}
}
}
}
}