-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetjson.cpp
94 lines (84 loc) · 2.05 KB
/
getjson.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
#include "jsoncpp.cpp"
#include "json/json.h"
#include<iostream>
#include<vector>
#include<fstream>
#include<regex>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
using namespace Json;
map<string, int> nums;
map<string, bool> bylo;
set< pair<int, int > > s;
int t;
struct ziom {
int id;
string year, name;
};
ziom node[1000];
int trans[1000];
int inf[1000];
bool comp (ziom a, ziom b)
{
if (a.year == b.year)
return a.name < b.name;
return a.year < b.year;
}
int main ()
{
Value root;
ifstream input("sparql-clean.json");
input >> root;
ofstream output("links.tsv");
ofstream nodes("nodes0.tsv");
Value links = root["results"]["bindings"];
output << "source\ttarget" << endl;
nodes << "name\tyear\tinf" << endl;
int it = 0;
for (int i = 0; i < links.size(); i++)
{
// regex_search(links[i]["A"]["value"].asString(), a, reg);
//regex_replace(a, dolnik, " ");
// cout << "aaa" << endl;
string aname = links[i]["A"]["value"].asString();
string bname = links[i]["B"]["value"].asString();
if (bylo.find(aname) == bylo.end())
{
bylo[aname] = 1;
node[it].year = links[i]["YA"]["value"].asString();
node[it].name = aname;
node[it].id = it;
nums[aname] = it++;
}
if (bylo.find(bname) == bylo.end())
{
bylo[bname] = 1;
node[it].year = links[i]["YB"]["value"].asString();
node[it].name = bname;
node[it].id = it;
nums[bname] = it++;
}
if (aname == "http://dbpedia.org/resource/Predrag_Finci" || aname == "http://dbpedia.org/resource/Jesús_Padilla_Gálvez")
cout << "fix "<< aname << endl, s.insert(make_pair(nums[bname], nums[aname]));
else
s.insert(make_pair(nums[aname], nums[bname]));
// output << nums[aname] << '\t' << nums[bname] << endl;
}
// cout << "pozdro" << endl;
sort(node, node+it, comp);
for (int i = 0; i < it; i++)
{
trans[node[i].id] = i;
}
for (auto a : s)
{
inf[trans[a.first]]++;
output << trans[a.first] << '\t' << trans[a.second] << endl;
}
for (int i = 0; i < it; i++)
{
nodes << node[i].name << "\t" << node[i].year << "\t" << inf[i] << endl;
}
}