-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
252 lines (221 loc) · 7.48 KB
/
index.php
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php
class Link {
// variables
public $node1;
public $node2;
public $link = 0;
public function __construct($a1, $a2, $a3) {
$this->node1 = $a1;
$this->node2 = $a2;
$this->link = $a3;
}
public function show() {
echo $this->node1 . " " . $this->node2 . " " . $this->link . "<br/>";
}
// methods
public function update() {
$this->link = $this->link + 1;
}
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}
}
}
function printPublications($xmlfile) {
// put your code here
$xml = simplexml_load_file($xmlfile) or die("Error: Cannot create object");
//echo "<pre>";
//print_r($xml);
//echo "</pre>";
$lastYear = $xml->publications->publication[0]->year;
echo '<div id = "PublicationList">'
. '<div class="year">'
. '<p>' . $lastYear . '</p><ul>';
foreach ($xml->publications->publication as $publication) {
if (strcmp($lastYear, $publication->year) != 0) {
$lastYear = $publication->year;
echo '</ul></div>'
. '<div class="year">'
. '<p>' . $lastYear . '</p><ul>';
}
foreach ($publication->author as $author) {
$author_arr[] = $author;
}
echo '<li><div class= "publication">'
. '<p>' //open new publication view
. '<strong>' . implode(", ", $author_arr) . '</strong>';
unset($author_arr);
echo ' <a href="' . $publication->post . '" target="_blank">' . $publication->title . '</a>.';
if (!empty($publication->booktitle)) {
echo ' In <i>' . $publication->booktitle . '</i>,';
}
if (!empty($publication->pages)) {
echo ' pp. ' . $publication->pages . '.';
}
if (!empty($publication->publisher)) {
echo ' ' . $publication->publisher . ', ';
}
echo ' ' . $publication->year;
if (!empty($publication->source)) {
echo ' <a href="' . $publication->source . '" target="_blank"><img src="images/pdf2.png" title="Download PDF File"/></a>';
}
if (!empty($publication->oro)) {
echo ' <a href="' . $publication->oro . '" target="_blank"><img src="images/oro2.png" title="Open Research Online (ORO) Link"/></a>';
}
if (!empty($publication->website)) {
echo ' <a href="' . $publication->website . '" target="_blank"><img src="images/website2.png" title="Visit External Website"/></a>';
}
if (!empty($publication->ee)) {
echo ' <a href="' . $publication->ee . '" target="_blank"><img src="images/doi.png" title="DOI | Digital Object Identifier"/></a>';
}
if (!empty($publication->rash)) {
echo ' <a href="' . $publication->rash . '" target="_blank"><img src="images/rash.png" title="RASH | Research Articles in Simplified HTML"/></a>';
}
echo '</p>'
. '</div></li>';
}
echo '</ul></div>'
. '</div>';
}
function checkGraph($xmlfile, $graphfile) {
if (!file_exists($graphfile)) {
createGraph($xmlfile, $graphfile);
} else {
if (filemtime($xmlfile) >= filemtime($graphfile)) {
createGraph($xmlfile, $graphfile);
}
}
}
function createGraph($xmlfile, $graphfile) {
// echo "Creating file $graphfile now!!!<br />";
$xml = simplexml_load_file($xmlfile) or die("Error: Cannot create object");
// loading authors
foreach ($xml->publications->publication as $publication) {
foreach ($publication->author as $author) {
$author_arr[] = $author;
}
}
$uniqueauths = array_unique($author_arr);
$auths = array();
$auths = array_fill_keys($uniqueauths, 0);
//unique authors + num of publications
for ($i = 0; $i < count($author_arr); $i++) {
$auths[(string) $author_arr[$i]] = $auths[(string) $author_arr[$i]] + 1;
}
//loading coauthorship
$cooc = array();
// foreach ($uniqueauths as $author) {
// foreach ($uniqueauths as $author2) {
// if (strcmp($author, $author2) != 0) {
// $cooc[$author . $author2] = new Link($author, $author2);
// //$cooc[$author . $author2]->show();
// }
// }
// }
unset($author_arr);
// print_r($cooc);
foreach ($xml->publications->publication as $publication) {
foreach ($publication->author as $author) {
$author_arr[] = $author;
}
// print_r($author_arr);
// echo "weilaa<br/>";
foreach ($author_arr as $author) {
foreach ($author_arr as $author2) {
if (strcmp($author, $author2) != 0) {
//echo $author . $author2;
if (array_key_exists($author . $author2, $cooc)) {
$cooc[$author . $author2]->update();
} else {
$cooc[$author . $author2] = new Link($author, $author2, 1);
}
}
}
}
unset($author_arr);
}
//printing graph on a file
$nodes = array();
$ids = array();
$links = array();
$i = 0;
foreach ($auths as $key => $value) {
$ids[$key] = "n" . $i;
$tmp_node = array(
'id' => "n" . $i,
'label' => $key,
'x' => rand(0, 15),
'y' => rand(0, 15),
'color' => "#06c",
'size' => $value
);
$nodes[$i] = $tmp_node;
$i++;
}
$graph["nodes"] = $nodes;
$i = 0;
$duplicates = array();
foreach ($cooc as $key => $value) {
$alternativeKey = $value->node2 . $value->node1;
if (array_key_exists($alternativeKey, $duplicates)) {
//do nothing
} else {
$tpmlabel = (1 < $value->link) ? $value->link . ' Co-authored Publications' : '';
$tmp_link = array(
'id' => "e" . $i,
'source' => $ids[(string) $value->node1],
'target' => $ids[(string) $value->node2],
'color' => "#eee",
'type' => 'curve',
'label' => $tpmlabel,
'size' => $value->link
);
$links[$i] = $tmp_link;
$i++;
//avoid the alternative
$duplicates[$key] = 'done';
}
}
unset($duplicates);
$graph["edges"] = $links;
$fp = fopen($graphfile, 'w');
fwrite($fp, json_encode($graph));
fclose($fp);
// echo "<pre>";
// print_r($graph);
// //echo json_encode($graph);
// echo "</pre>";
}
function printGraph($graphfile) {
// echo '<div id="container">
// <div id="graph-container">';
require("./graph_json.html");
// echo '</div></div>';
}
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel='stylesheet' type='text/css' href='myCss.css' />
</head>
<body>
<div id="container">
<!-- <div id="PublicationList">Scroll down to see the graph</div>-->
<?php
$xmlfile = "myPubs.xml";
$graphfile = "myCoauth.json";
checkGraph($xmlfile, $graphfile);
printPublications($xmlfile);
printGraph($graphfile);
?>
</div>
</body>
</html>