-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.php
More file actions
268 lines (252 loc) · 8.51 KB
/
Copy pathquery.php
File metadata and controls
268 lines (252 loc) · 8.51 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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/*
Code snippets adapted from http://graphite.ecs.soton.ac.uk/sparqllib/
Use of sparqllib.php
Simple library to query SPARQL from PHP.
©2010-12 Christopher Gutteridge, University of Southampton.
Under LGPL license
*/
/*
Note Author (Klaas Andries de Graaf):
Querys and data is often hardcoded (not dynamic from e.g. CASE tool database) with examples
to allow for easy understanding of code.
Making this fully dynamic + linking it to database/code repository is easy, but introduces more complex code to read for reviewers.
*/
require_once('sparqllib.php');
//$db = sparql_connect('http://dbpedia.org/sparql');
$db = sparql_connect('http://www.archimind.nl/archimindLOD/index.php/sparql');
//$query = "SELECT ?film
//WHERE { ?film <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:French_films> }";
//echo $_POST['query'];
//echo strlen(trim($_POST['query']));
//echo $_POST['query'];
//if ($_POST['query'] !== ""){$query = $_POST['query'];}
if (strlen(trim($_POST['query']))){$query = $_POST['query'];}
else{
$query = "PREFIX AKO: <http://www.archimind.nl/archimindLOD/index.php/view/r/sadocontology1.owl:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE { ?uri rdf:type AKO:Pattern .
?uri AKO:description ?description .
?uri AKO:knowledge_is_located_in ?wikipage .
?uri rdf:seeAlso ?DBpedia}";
}
$result = sparql_query($query);
$fields = sparql_field_array($result);
//echo $_GET['query'];
if ($_POST['case'] == 'reqs1'){
echo " <br \>- [Related requirements in ArchiMind: ";
if (sparql_num_rows( $result ) > 0)
{
while($row = sparql_fetch_array($result))
{
foreach($fields as $field)
{
if(strpos($row[$field], "ttp:") !== false)
{echo "<a href='".$row[$field] . "' target='_blank'>";}
else
{echo $row[$field] . "</a>, ";}
//print"$row[$field] <br\>";
}
}
}
else
{
echo '<b>ARCHITECTURAL RULE VIOLATION - NO RELATED REQUIREMENTS <a href="http://www.archimind.nl/archimindLOD/index.php/view/r/sadocontology1.owl%3ABusiness_rules_engine" target="_blank">Change</a></b>';
}
echo '] <br \>- <a href="#" onclick="predefined(11);">[find related decisions in ArchiMind]</a>';
}
else if ($_POST['case'] == 'decs1'){
echo ' <br \>- <a href="#" onclick="predefined(10);">[find related requirements in ArchiMind]</a> <br \>- [Related decisions in ArchiMind: ';
if (sparql_num_rows( $result ) > 0)
{
while($row = sparql_fetch_array($result))
{
foreach($fields as $field)
{
if(strpos($row[$field], "ttp:") !== false)
{echo "<a href='".$row[$field] . "' target='_blank'>";}
else
{echo $row[$field] . "</a>, ";}
//print"$row[$field] <br\>";
}
}
}
else
{
echo '<b>ARCHITECTURAL RULE VIOLATION - NO RELATED DECISIONS <a href="http://www.archimind.nl/archimindLOD/index.php/view/r/sadocontology1.owl%3ABusiness_rules_engine" target="_blank">Change</a></b>';
}
echo '] ';
}
//else{
//echo ' <br \>- <a href="#" onclick="predefined(10);">[find related requirements in ArchiMind]</a> <br \>- <a href="#" onclick="predefined(11);">[find related decisions in ArchiMind]</a>';
//}
if ($_POST['case'] == 'reqs2'){
echo " <br \>- [Related requirements in ArchiMind: ";
if (sparql_num_rows( $result ) > 0)
{
while($row = sparql_fetch_array($result))
{
foreach($fields as $field)
{
if(strpos($row[$field], "ttp:") !== false)
{echo "<a href='".$row[$field] . "' target='_blank'>";}
else
{echo $row[$field] . "</a>, ";}
//print"$row[$field] <br\>";
}
}
}
else
{
echo '<b>ARCHITECTURAL RULE VIOLATION - NO RELATED REQUIREMENTS <a href="http://www.archimind.nl/archimindLOD/index.php/view/r/sadocontology1.owl%3ATransformer" target="_blank">Change</a>]</b>';
}
echo '] <br \> - <a href="#" onclick="predefined(13);">[find related decisions in ArchiMind]</a>';
}
else if ($_POST['case'] == 'decs2'){
echo ' <br \>- <a href="#" onclick="predefined(12);">[find related requirements in ArchiMind]</a> <br \>- [Related decisions in ArchiMind: ';
if (sparql_num_rows( $result ) > 0)
{
while($row = sparql_fetch_array($result))
{
foreach($fields as $field)
{
if(strpos($row[$field], "ttp:") !== false)
{echo "<a href='".$row[$field] . "' target='_blank'>";}
else
{echo $row[$field] . "</a>, ";}
//print"$row[$field] <br\>";
}
}
}
else
{
echo '<b>ARCHITECTURAL RULE VIOLATION - NO RELATED DECISIONS <a href="http://www.archimind.nl/archimindLOD/index.php/view/r/sadocontology1.owl%3ATransformer" target="_blank">Change</a></b>';
}
echo ']';
}
if ($_POST['case'] == 'selectQ2' || $_POST['case'] == 'selectQ4')
{
if ($_POST['case'] == 'selectQ2'){echo "<select id='Q2parameter'>";}
else{echo "<select id='Q4parameter'>";}
while( $row = sparql_fetch_array( $result ) )
{
print "<option ";
foreach( $fields as $field )
{
if(strpos($row[$field], "ttp:") !== false)
{
print "value='" . substr($row[$field], (strpos($row[$field], ".owl:")+ 5)) . "' ";
if ($_POST['case'] == 'selectQ2' && strpos($row[$field], "Security") !== false){echo "selected ";}
else if ($_POST['case'] == 'selectQ4' && strpos($row[$field], "Compatability") !== false){echo "selected ";}
echo ">";
}
//<a href='".$row[$field] . "' target='_blank'>" . $row[$field] . "</a></td>";
else
{print "$row[$field]";}
}
print "</option>";
}
echo "</select>";
}
else if ($_POST['case'] == 'selectClasses')
{
echo "<select id='selectClasses'>";
while( $row = sparql_fetch_array( $result ) )
{
print "<option ";
foreach( $fields as $field )
{
if(strpos($row[$field], "ttp:") !== false)
{
print "value='" . substr($row[$field], (strpos($row[$field], ".owl:")+ 5)) . "'>";
}
//<a href='".$row[$field] . "' target='_blank'>" . $row[$field] . "</a></td>";
else
{print "$row[$field]";}
}
print "</option>";
}
echo "</select>";
}
else if ($_POST['case'] == 'instancequery')
{
$result = sparql_query($query);
$fields = sparql_field_array($result);
//}
?>
<b>Results (<?php echo sparql_num_rows( $result ); ?>): <input class="button" type="button" id="editor" name="editor" value="View and Adapt SPARQL Query" onclick="$('#sendquery').focus()"></b>
<?php
//print "<p>Number of results: ".sparql_num_rows( $result )." results.</p>";
print "<table class='CSSTableGenerator' border='1'>";
print "<tr>";
foreach( $fields as $field )
{
print "<th>$field</th>";
}
print "<th>More information</th>";
print "</tr>";
while( $row = sparql_fetch_array( $result ) )
{
print "<tr>";
foreach( $fields as $field )
{
if(strpos($row[$field], "ttp:") !== false)
{print "<td><a href='".$row[$field] . "' target='_blank'>" . $row[$field] . "</a></td>";
?><td><input type="button" class="button" value="Retrieve more information and related AK" onclick="detailsquery('<?php echo substr($row[$field], (strpos($row[$field], ".owl:")+ 5)) ?>')"><br \></td><?php
}
else
{print "<td>$row[$field]</td>";}
}
print "</tr>";
}
print "</table>";
}
else{
// echo ' <br \>- <a href="#" onclick="predefined(12);">[find related requirements in ArchiMind]</a> <br \>- <a href="#" onclick="predefined(13);">[find related decisions in ArchiMind]</a>';
//
//if($_POST['case'] == 'decs1' || $_POST['case'] == 'reqs1' || $_POST['case'] == 'decs2' || $_POST['case'] == 'reqs2')
//{
$result = sparql_query($query);
$fields = sparql_field_array($result);
//}
?>
<b>Results (<?php echo sparql_num_rows( $result ); ?>): <input class="button" type="button" id="editor" name="editor" value="View and Adapt SPARQL Query" onclick="$('#sendquery').focus()"></b>
<?php
//print "<p>Number of results: ".sparql_num_rows( $result )." results.</p>";
print "<table class='CSSTableGenerator' border='1'>";
print "<tr>";
foreach( $fields as $field )
{
print "<th>$field</th>";
}
print "</tr>";
while( $row = sparql_fetch_array( $result ) )
{
print "<tr>";
foreach( $fields as $field )
{
if(strpos($row[$field], "ttp:") !== false)
{print "<td><a href='".$row[$field] . "' target='_blank'>" . $row[$field] . "</a></td>";}
else
{print "<td>$row[$field]</td>";}
}
print "</tr>";
}
print "</table>";
/*
while($row = sparql_fetch_array($result))
{
foreach($fields as $field)
{
if(strpos($row[$field], "ttp:") !== false)
{echo "<a href='".$row[$field] . "' target='_blank'>" . $row[$field] . "</a><br/>";}
else
{echo $row[$field] . "<br/>";}
//print"$row[$field] <br\>";
}
}
*/
}
?>