-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
223 lines (215 loc) · 6.31 KB
/
index.html
File metadata and controls
223 lines (215 loc) · 6.31 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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<title>Explore Neuro Imaging Data Model Experiment Terms</title>
<link href="./lib/nidm-term-search.css" type="text/css" rel="stylesheet"/>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://unpkg.com/vue"></script>
<script type='text/javascript' src="./lib/rdfstore_min.js">
</script>
<script type="text/x-template" id="grid-template">
<table>
<thead>
<tr>
<th v-for="key in columns">
{{ key }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="entry in data">
<td v-for="key in columns">
{{entry[key]}}
</td>
</tr>
</tbody>
</table>
</script>
</head>
<body>
<br>
<div id="gridC">
<p> <h3>Select NIDM OWL File </h3></p>
<select v-model="selected">
<option disabled value="">Please select one</option>
<option v-for="option in options" v-bind:value="option.value">
{{option.text}}
</option>
</select>
<p>Selected: {{ selected }}</p>
<br>
<br>
<demo-grid
:data="prefixData"
:columns="prefixColumns">
</demo-grid>
<br>
<br>
<demo-grid
:data="gridData"
:columns="gridColumns">
</demo-grid>
</div>
<script>
let prefixes = {}
let prefixArray = []
let query = " PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\
PREFIX obo:<http://purl.obolibrary.org/obo/>\
SELECT *\
WHERE { ?subject rdfs:label ?label ;\
obo:IAO_0000115 ?desc .\
} \
"
// register the grid component
Vue.component('demo-grid', {
template: '#grid-template',
props: {
data: Array,
columns: Array
},
data: function () {
var sortOrders = {}
this.columns.forEach(function (key) {
sortOrders[key] = 1
})
return {
sortKey: '',
sortOrders: sortOrders
}
}
})
var gridC = new Vue({
el: '#gridC',
data: {
selected:'https://raw.githubusercontent.com/smpadhy/nidm-term-search/master/owl/nidm-experiment.owl',
options:[
{text:'NIDM-Experiment', value:'https://raw.githubusercontent.com/smpadhy/nidm-term-search/master/owl/nidm-experiment.owl'},
{text:'NIDM-DICOM', value:'https://raw.githubusercontent.com/incf-nidash/dicom-ontology/master/dicom_ontology_nlx.owl'},
{text:'NIDM-Results', value:'https://raw.githubusercontent.com/smpadhy/nidm-term-search/master/owl/nidm-results_130.owl'}
],
gridColumns: [],
gridData: [],
prefixColumns: [],
prefixData:[]
},
computed: {
showDefaultOwl:{
get: function(){
},
// setter
set: function (gurl) {
$.ajax({
type: "GET",
url: gurl,
success: function(data1){
successCallBack(data1,gridC)
}
})//ajax call
}
}
},
watch: {
'selected': function() {
console.log("gridC.selected", gridC.selected)
$.ajax({
type: "GET",
url: gridC.selected,
success: function(data){
successCallBack(data,gridC)
}
})//ajax call
}
}//end of watch
})
gridC.showDefaultOwl = 'https://raw.githubusercontent.com/smpadhy/nidm-term-search/master/owl/nidm-experiment.owl'
function successCallBack(data,gridComponent){
prefixes = {}
let lines = data.split("\n")
for(let i=0;i<lines.length; i++){
let line = lines[i].split(" ")
if(line[0] == "@prefix"){
substrPrefix = line[2].substring(1,line[2].length-2)
if(line[1] == ":"){
console.log("TODO")
prefixes[substrPrefix] = "turtle"
}else{
let pf = line[1].substring(0,line[1].length-1)
prefixes[substrPrefix] = pf
}
}else if(line[0] == "@base"){
substrPrefix = line[1].substring(1,line[2].length-2)
prefixes[substrPrefix] = "owl"
}else{
console.log("prefixes--: ", prefixes)
break;
}
}
console.log("split data: --\n", prefixes)
new rdfstore.Store(function(err, store) {
store.load("text/turtle",data,function(err, results){
if(err){
console.log(err)
}
store.execute(query,function(success,results) {
let items = results
let triples = []
let triple = {}
let prefixItems = []
let prefixItem = {}
for(let i = 0 ; i<items.length; i++){
//triple['URI'] = items[i]['subject'].value
triple['Term'] = items[i]['label'].value
triple['Description'] = items[i]['desc'].value
prefixItem = getPrefixItem(items[i]['subject'].value)
triple['URI'] = prefixItem['termWithPrefix']
if(!isExist(triple, triples,'URI')){
triples.push(triple)
}
if(!isExist(prefixItem, prefixItems,'Prefix')){
console.log("prefixItem:", prefixItem.Prefix)
prefixItems.push(prefixItem)
}
triple = {}
prefixItem = {}
}
console.log("demo.selected", gridComponent.selected)
gridComponent.gridColumns = ['Term', 'Description', 'URI']
gridComponent.gridData = triples
gridComponent.prefixColumns = ['Prefix', 'URI']
gridComponent.prefixData = prefixItems
})//end of store execute
})//end of load
})//rdf store
} //end of successCallBack
function isExist(obj, arr,prop){
for(index=0;index < arr.length; index++){
let x = arr[index]
if(x[prop] === obj[prop])
return true
}
return false
}
function getPrefixItem(uri){
let prefixItem = {}
let pfname = uri.split("#")
let iri = uri.split("/")
for(item in prefixes){
if(uri.indexOf(item)!=-1){
prefixItem['Prefix'] = prefixes[item]
prefixItem['URI'] = item
if(pfname.length>1){
let parr = iri[iri.length-1].split("#")
prefixItem['termWithPrefix'] = prefixes[item]+ ":" + parr[1]
}else{
prefixItem['termWithPrefix'] = prefixes[item]+ ":" + iri[iri.length-1]
}
}
}
return prefixItem
}
</script>
</body>
</html>