forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategoryPane.js
More file actions
177 lines (154 loc) · 6.16 KB
/
categoryPane.js
File metadata and controls
177 lines (154 loc) · 6.16 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
/* Category Pane
**
** This outline pane allows the user to select which sublclasses
** something is a member of in a tree-organized class hierarchy.
** This could equally well be used for any other hierarchical set of things
** such as nested geograpgical regions or nested time periods,
** or for a class of a related thing, such of class of person in the picture.
** Maybe this hsoul dbe split off as a widget for tagging within other panes.
*/
// These used to be in js/init/icons.js but are better in the pane.
var UI = require('solid-ui')
module.exports = {
icon: UI.icons.originalIconBase + 'icons/22-categorize.png',
name: 'category',
// Does the subject deserve a categorizing pane?
label: function (subject) {
var kb = UI.store
var t = kb.findTypeURIs(subject)
// @@@ t = kb.topTypeURIs(t)
var classes = 0
for (var u in t) classes++
// @@@@ if (classes==0) return null ; // None, suppress pane
// Not if a class itself (maybe need a different pane for that):
if (t['http://www.w3.org/2000/01/rdf-schema#Class']) return null
if (t['http://www.w3.org/2002/07/owl#Class']) return null
return 'Categorize ' + classes; // Yes under other circumstances (while testing at least!)
},
render: function (subject, myDocument) {
var kb = UI.store
var div = myDocument.createElement('div')
div.setAttribute('class', 'categoryPane')
var types = kb.findTypeURIs(subject)
var tops = kb.topTypeURIs(types)
var bots = kb.bottomTypeURIs(types)
// ///////////// debug
/*
var str = ""
for (var t in types) str = str + t + ", "
var debug = div.appendChild(myDocument.createTextNode('Types: '+str)) // @@@
var str = ""
for (var t in bots) str = str + t + ", "
var debug = div.appendChild(myDocument.createTextNode('. Bots: '+str)) // @@@
*/
function domForClass (c, force) {
var tr = myDocument.createElement('TR')
tr.setAttribute('class', 'categoryClass')
var anchor = myDocument.createElement('A')
if (c.uri) anchor.setAttribute('href', c.uri)
anchor.setAttribute('class', c.uri in types ? 'categoryIn' : 'categoryOut')
if (c.uri in bots) anchor.setAttribute('class', 'categoryBottom')
var lab = UI.utils.label(c, true)
if (c.uri in types) lab += ' *'
anchor.appendChild(myDocument.createTextNode(lab))
tr.appendChild(anchor)
// Add provenance info - which statement makes us beleive this
if (c.uri) {
var st = types[c.uri]
if (st) {
if (st.uri) { // just a subsumption
/* nothing */
} else if (st.why) { // specific statement
var anchor = myDocument.createElement('A')
anchor.appendChild(myDocument.createTextNode(
' (' +
UI.utils.label(st.subject) + ' ' +
UI.utils.label(st.predicate) + ' ' +
UI.utils.label(st.object) + ')'))
if (st.why.uri) anchor.setAttribute('href', st.why.uri)
anchor.setAttribute('class', 'categoryWhy')
tr.appendChild(anchor)
}
}
}
var table = null
/*
var makeSelectForSubs = function(subs, multiple) {
var n = 0; var uris ={} // Count them
for (var i=0; i < subs.length; i++) {
var sub = subs[i]
if (sub.uri in uris) continue
uris[sub.uri] = true; n++
}
if (n>0) {
var select = myDocument.createElement('select')
if (multiple) select.setAttribute('multiple', 'true')
//@@ Later, check whether classes are disjoint.
select.innerHTML = "<option>-- classify --</option>"
for (var uri in uris) {
var option = myDocument.createElement('option')
option.appendChild(myDocument.createTextNode(UI.utils.label(kb.sym(uri))))
option.setAttribute('name', uri)
if (uri in types) option.setAttribute('selected', 'true')
select.appendChild(option)
}
return select
}
return null
} // makeSelectForSubs
*/
if (kb.any(c, kb.sym('http://www.w3.org/2002/07/owl#disjointUnionOf'))) {
var sel = UI.widgets.makeSelectForCategory(
myDocument, kb, subject, c,
subs, false) // Not multiple
}
/*
var subClassesAsNT = {}
if (disjointSubclassLists.length) {
for (j=0; j<disjointSubclassLists.length; j++) {
td.appendChild(myDocument.createTextNode('subs:'+subs))
var subs = disjointSubclassLists[j].elements
var sel = UI.widgets.makeSelectForCategory(
myDocument, kb, subject, c,
subs, false) // Not multiple
if (sel) tr.appendChild(sel)
for (var i=0; i<subs.length; i++) {
subClassesAsNT[subs[i].toNT()] = true // Could be blank node
}
}
}
*/
var subs = kb.each(undefined, kb.sym('http://www.w3.org/2000/01/rdf-schema#subClassOf'), c)
if (subs) {
if (!table) {
table = myDocument.createElement('TABLE')
table.setAttribute('class', 'categoryTable')
tr.appendChild(table)
}
var uris = {}; // remove duplicates (why dups?) and count
var n = 0
for (var i = 0; i < subs.length; i++) {
var sub = subs[i]
if (sub.uri in uris) continue
uris[sub.uri] = true; n++
}
// @@
for (var uri in uris) {
if (uri in types) {
table.appendChild(domForClass(kb.sym(uri), false))
// } else if (c.uri && ((c.uri in bots) || (c.uri in categorizables))) {
// table.appendChild(domForClass(kb.sym(uri), false))
}
}
}
return tr
}
for (var u in tops) {
var c = kb.sym(u)
var tr = domForClass(c)
div.appendChild(tr)
}
return div
}
}
// ends