/
getCytoscapeJSON.php
131 lines (100 loc) · 3.6 KB
/
getCytoscapeJSON.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
<?php
require_once('vendor/autoload.php');
use Everyman\Neo4j\Cypher\Query;
$client = new Everyman\Neo4j\Client('localhost', 7474);
$client->getTransport()
->setAuth('neo4j', 'muresearch');
/*
function findMaxNumCoauthoredPapers($client, $unifiedName){
$q = "match (u:Person {name: \"".$unifiedName."\"}) - [r:COAUTHORED] - (:Person) return max(r.numOfPapers) as num";
$query = new Query($client, $q);
$result = $query->getResultSet();
foreach($result as $r){
return $r['num'];
}
}
function findMaxNumPublication($client, $unifiedName){
$q = "match (u:Person {name: \"".$unifiedName."\"}) - [r:COAUTHORED] - (u2:Person) return u.publicationNum as maxMain,max(u2.publicationNum) as maxOthers";
$query = new Query($client, $q);
$result = $query->getResultSet();
foreach($result as $r){
if($r['maxMain'] >= $r['maxOthers']){
return $r['maxMain'];
}
else{
return $r['maxOthers'];
}
}
}
*/
function mapSize($maxSize, $minSize, $data){
if($data <= ($maxSize - $minSize)){
return $data+$minSize;
}
else{
return $maxSize;
}
}
if(isset($_POST['data']) && !empty($_POST['data'])){
$stringJSON = stripslashes($_POST['data']);
$d = json_decode($stringJSON, true);
$unifiedName = $d['name'];
//$maxNodeSizePubNum = findMaxNumPublication($client, $unifiedName);
$maxNodeSize = 50;
$minNodeSize = 15;
//$maxEdgeWidthCoauthorNum = findMaxNumCoauthoredPapers($client, $unifiedName);
$maxEdgeWidth = 10;
$minEdgeWidth = 1;
$q = "match (u:Person {name: \"".$unifiedName."\"})-[r:COAUTHORED]-(u2:Person)
return u.name as mainAuthor,
u.publicationNum as mainAuthorPubNum,
u.isProfessor as mainAuthorProfessor,
r.numOfPapers as numCoauthored,
u2.name as coAuthor,
u2.fromMU as fromMU,
u2.publicationNum as coAuthorPubNum,
u2.isProfessor as coAuthorProfessor";
$query = new Query($client, $q);
$result = $query->getResultSet();
$nodeArray = array();
$edgeArray = array();
$setMain = 0;
foreach($result as $r){
if( $setMain == 0){
$nodeArray[] = array("data" => array("id"=>$r['mainAuthor'],
"name"=>$r['mainAuthor'],
"isProfessor"=>$r['mainAuthorProfessor'],
"nodeSize"=> mapSize($maxNodeSize, $minNodeSize, $r['mainAuthorPubNum']))
//"nodeSize" => 30)
);
$setMain = 1;
}
$nodeArray[] = array("data" => array("id"=>$r['coAuthor'],
"name"=>$r['coAuthor'],
"fromMU"=>$r['fromMU'],
"isProfessor"=>$r['coAuthorProfessor'],
"nodeSize"=> mapSize($maxNodeSize, $minNodeSize, $r['coAuthorPubNum']))
//"nodeSize"=>10)
);
$edgeArray[] = array("data" => array("number" => $r['numCoauthored'],
"source"=>$r['mainAuthor'],
"target"=>$r['coAuthor'],
"edgeSize" => mapSize($maxEdgeWidth, $minEdgeWidth, $r['numCoauthored']))
);
}
$q = "match (u1) - [r:COAUTHORED] - (u2)
where u1 - [:COAUTHORED] - ({name: \"".$unifiedName."\"})
AND u2 - [:COAUTHORED] - ({name: \"".$unifiedName."\"})
AND ID(u1) < ID(u2)
return u1.name as author1, r.numOfPapers as numCoauthored, u2.name as author2";
$query = new Query($client, $q);
$result = $query->getResultSet();
foreach($result as $r){
$edgeArray[] = array("data" => array("number" => $r['numCoauthored'],
"source" => $r['author1'],
"target" => $r['author2'],
"edgeSize" => mapSize($maxEdgeWidth, $minEdgeWidth, $r['numCoauthored']))
);
}
echo json_encode(array("nodes" => $nodeArray, "edges" => $edgeArray));
}