-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoExample.js
More file actions
167 lines (134 loc) · 4.44 KB
/
Copy pathDemoExample.js
File metadata and controls
167 lines (134 loc) · 4.44 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
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
/**
* sones GraphDB JavaScript Client Library
* Copyright (C) 2007-2011 sones GmbH - http://www.sones.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Demo: to show the usage of the sones-javascriptclient for GraphDB(2.0)
* Please see the README.txt
*
* @author Michael (Schille) Schilonka
*/
var cont = "<pre>";
function DemoExample(gql){
var QueryResult = doQuery(gql)
var QueryMeta = QueryResult.QueryMeta;
var VertexViewList = QueryResult.VertexViewList;
var div = document.getElementById("output");
if (true) {
// gql string
cont += "QueryString: " + QueryMeta.getQueryString() + "<br/>";
// result type
cont += "ResultType: <b>" + QueryMeta.getResultType() + "</b><br/>";
//duration in ms
cont += "Duration: " + QueryMeta.getDuration() + "<br/>";
//errors
cont += "Errors:" + QueryMeta.getError() + "<br/>";
//vertices
cont += "Vertices:<br/>";
i = 0;
$.each(VertexViewList,function(){
cont += printVertex(this, 0, i);
i++;
});
}
else {
cont = "<b>Service unavailable!</b>"
}
cont += "</pre>";
div.innerHTML = cont;
document.getElementById("gql").value = "";
};
function printVertex(myVertex, depth, i){
var tabs = "";
cont = "";
depth++;
for (var k = 0; k <= depth; k++){
tabs += "  ";
};
cont += tabs + "<div style='border:solid; padding:5px; width:90%'>" + tabs + "<b>Vertex " + i + ":</b></br>" + tabs + "\\<br/>";
cont += tabs + "|<br/>";
cont += tabs + "|Properties:<br/>";
cont += tabs + "|<br/>";
var properties = myVertex.getProperties();
if (properties.length != 0) {
$.each(properties, function(){
cont += "<div style='border:solid 1px, width:90%'>"
cont += tabs + "ID: " + this.ID + "<br/>";
cont += tabs + "Type: " + this.Type + "<br/>";
cont += tabs + "Value: " + this.Value + "<br/>";
cont += "</div></br>"
});
}
cont += tabs + "|<br/>";
cont += tabs + "|BinaryProperties:<br/>";
cont += tabs + "|<br/>";
var binary = myVertex.getBinaryProperties();
if(binary != undefined){
$.each(binary,function(){
cont += "<div style='border:solid 1px;padding:5px;width:90%'>"
cont += tabs + "ID: " + this.ID + "<br/>";
cont += tabs + "Content: " + this.Content + "<br/>";
cont += "</div></br>"
});
}
cont += tabs + "|<br/>";
cont += tabs + "|Edges:<br/>";
cont += tabs + "|has Edges: " + myVertex.hasEdges() + "</br>";
cont += tabs + "|<br/>";
var single = myVertex.getAllSingleEdges();
if(single.length != 0){
cont += printSingleEdges(single, tabs, depth);
}
var hyper = myVertex.getAllHyperEdges();
if(hyper.length != 0){
$(hyper).each(function(){
var sing = this.getSingleEdges();
if (sing.length != 0) {
cont += "<div style='border:dashed;padding:5px; width:90%'>";
cont += tabs + "<b> ->" + this.Name + "(" + this.type + ")" + "</b><br/>";
cont += printSingleEdges(sing, tabs, depth);
cont += "</div>";
}
});
}
cont += "</div>";
return cont;
}
function printSingleEdges(single, tabs,depth){
cont = "";
$.each(single,function(){
var props = this.getProperties();
cont += tabs + " ->" + this.Name +"(" + this.type + ")"+ "<br/>";
cont += "<div>"
cont += tabs + " \\<br/>";
cont += tabs + " |<br/>";
if (props != undefined) {
if (props.length != 0) {
$.each(properties, function(){
cont += "<div style='border:dotted 1px;width:90%'>"
cont += tabs + tabs + "ID: " + this.ID + "<br/>";
cont += tabs + tabs + "Type: " + this.Type + "<br/>";
cont += tabs + tabs + "Value: " + this.Value + "<br/>";
cont += "</div></br>"
});
}
}
cont += printVertex(this.getTargetVertex(), depth++, 0);
cont += "</div></br>";
});
return cont;
}