-
Notifications
You must be signed in to change notification settings - Fork 35
/
Graph.jsp
199 lines (180 loc) · 7.42 KB
/
Graph.jsp
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
<%@ include file="Prelude.jsp" %>
<html>
<head>
<title>Sigma KB Browser</title>
</head>
<body BGCOLOR=#FFFFFF>
<script>
function getWidth() {
if (self.innerWidth) {
return self.innerWidth;
}
else if (document.documentElement && document.documentElement.clientHeight) {
return document.documentElement.clientWidth;
}
else if (document.body) {
return document.body.clientWidth;
}
return 0;
}
function setWidth(id) {
// document.getElementById(id).value = screen.width * 0.9;
document.getElementById(id).value = Math.round(getWidth() * 0.9);
}
</script>
<%
/** This code is copyright Teknowledge (c) 2003, Articulate Software (c) 2003-2017,
Infosys (c) 2017-present.
This software is released under the GNU Public License
<http://www.gnu.org/copyleft/gpl.html>.
Please cite the following article in any publication with references:
Pease A., and Benzmüller C. (2013). Sigma: An Integrated Development Environment
for Logical Theories. AI Communications 26, pp79-97. See also
http://github.com/ontologyportal
*/
// If the request parameter can appear more than once in the query string, get all values
String[] values = request.getParameterValues("columns");
//if (values != null) {
// for (int i = 0; i < values.length; i++)
// System.out.println(" value[" + i + "] == " + values[i]);
//}
Graph g = new Graph();
String view = request.getParameter("view");
String inst = request.getParameter("inst");
String all = request.getParameter("all");
String fileRestrict = request.getParameter("fileRestrict");
if (fileRestrict == null || fileRestrict.equals("null"))
fileRestrict = "";
if (view == null)
view = "text";
if (term == null || term.equals("null")) term = "Process";
String relation = request.getParameter("relation");
if (relation == null || relation.equals("null") || relation.equals("")) {
if (KButilities.isRelation(kb,term))
relation = "subrelation";
else if (KButilities.isAttribute(kb,term))
relation = "subAttribute";
else
relation = "subclass";
}
String up = request.getParameter("up");
if (up == null) up = "1";
int upint = Integer.parseInt(up);
if (upint > 10)
upint = 1;
String down = request.getParameter("down");
if (down == null) down = "1";
int downint = Integer.parseInt(down);
if (downint > 10)
downint = 1;
int limitInt = 100;
String limit = request.getParameter("limit");
try {
limitInt = Integer.parseInt(limit);
if (limitInt > 100 || limitInt < 10)
limitInt = 100;
}
catch (NumberFormatException nfe) {
limit = "";
}
String[] items = request.getParameterValues("columns");
if (items != null) {
Iterator<String> it = g.columnList.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
g.columnList.put(key,"no");
}
for (int i = 0; i < items.length; i++)
g.columnList.put(items[i],"yes");
}
%>
<form action="Graph.jsp">
<%
String pageName = "Graph";
String pageString = "KB Graph";
%>
<%@include file="CommonHeader.jsp" %>
<table ALIGN="LEFT" WIDTH=80%><tr><TD BGCOLOR='#AAAAAA'><IMG SRC='pixmaps/1pixel.gif' width=1 height=1 border=0></TD></tr></table><BR>
<font face="Arial,helvetica"><b>Relation: </b>
<a href="Browse.jsp?kb=<%=kbName%>&term=<%=relation%>"> <%=relation%></a></font><p>
<%
/* Present the text layout (graph layout is in the else) */
if (view.equals("text")) {
Set<String> result = null;
boolean instBool = false;
if (!StringUtil.emptyString(inst) && inst.equals("inst"))
instBool = true;
if (limit != null && limit != "")
result = g.createBoundedSizeGraph(kb,term,relation,limitInt,instBool,language);
else
result = g.createGraph(kb,term,relation,Integer.parseInt(up),
Integer.parseInt(down),limitInt,instBool,language);
out.println("<p><table>\n");
for (String element : result) {
out.println(element);
}
out.println("</table></p>\n");
}
else { // it is a graph
int width = 500;
String widthStr = KBmanager.getMgr().getPref("graphWidth");
if (!StringUtil.emptyString(widthStr))
width = Integer.parseInt(widthStr);
String scrWidth = request.getParameter("scrWidth");
if (!StringUtil.emptyString(scrWidth))
width = Integer.parseInt(scrWidth);
String edges = "";
String fname = null;
boolean graphAvailable = false;
if (term != null && relation != null && kb != null && role.equalsIgnoreCase("admin")) {
fname = "GRAPH_" + kbName + "-" + term + "-" + relation;
try {
if (!StringUtil.emptyString(all))
relation = "all";
System.out.println("Graph.jsp: creating graph with limitInt=" + limitInt +
" and fileRestrict=" + fileRestrict);
graphAvailable = g.createDotGraph(kb,term,relation,Integer.parseInt(up),
Integer.parseInt(down),limitInt,fname,fileRestrict);
Thread.sleep(500); // give some time for the image to write to disc
}
catch (Exception ex) {
graphAvailable = false;
}
}
if (graphAvailable) {
out.println("<img src='graph/" + fname + ".dot.png'/>");
}
else {
out.println("<p><b>Error producing graph.</b></p>");
out.println(HTMLformatter.formatErrorsWarnings(g.errors,kb));
}
}
%>
Relation: <input type="text" size="30" name="relation" value="<%=relation %>">
Term: <input type="text" size="30" name="term" value="<%=term %>"><p>
Levels "above":<input type="text" size="2" name="up" value="<%=up %>">
Levels "below":<input type="text" size="2" name="down" value="<%=down %>">
Total term limit:<input type="text" size="2" name="limit" value="<%=limit %>">
Show instances: <input type="checkbox" name="inst" value="inst" <%= (inst != null && inst.equals("inst")) ? "checked" : "" %>><br>
All relations: <input type="checkbox" name="all" value="all" <%= (all != null && all.equals("all")) ? "checked" : "" %>>
Restrict to file:<input type="text" size="30" name="fileRestrict" value="<%=fileRestrict %>"> <br>
Columns to display:<%=HTMLformatter.createMultiMenu("columns",g.columnList) %>
<input type="hidden" value="" onLoad="setWidth(this)" name="scrWidth" id="scrWidth"/>
<script type="text/javascript">setWidth('scrWidth');</script>
<p>
<table border="0">
<tr>
<td>View format:</td>
<% if (role.equalsIgnoreCase("admin")) { %>
<td><input type="radio" name="view" value="graph" <%= (view.equals("graph")) ? "checked" : "" %>>graph</td>
<% } %>
<td><input type="radio" name="view" value="text" <%= (view.equals("text")) ? "checked" : "" %>>text</td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="submit">
</form>
<p>
<%@ include file="Postlude.jsp" %>
</body>
</html>