108
|
108
|
|
Library index
|
109
|
109
|
|
"""
|
110
|
110
|
|
|
111
|
|
- |
# Get a list of authors for searching
|
|
111
|
+ |
# Get a list of authors for search filters
|
112
|
112
|
|
authors = query("""
|
113
|
113
|
|
PREFIX library: <dokk:vocab:library:>
|
114
|
114
|
|
|
119
|
119
|
|
ORDER BY ?name
|
120
|
120
|
|
""")['results']['bindings']
|
121
|
121
|
|
|
122
|
|
- |
# Get a list of licenses for searching
|
|
122
|
+ |
# Get a list of licenses for search filters
|
123
|
123
|
|
licenses = query("""
|
124
|
124
|
|
PREFIX library: <dokk:vocab:library:>
|
125
|
125
|
|
PREFIX license: <dokk:vocab:license:>
|
134
|
134
|
|
ORDER BY ?id
|
135
|
135
|
|
""")['results']['bindings']
|
136
|
136
|
|
|
|
137
|
+ |
# Get a list of journals for search filters
|
|
138
|
+ |
journals = query("""
|
|
139
|
+ |
PREFIX library: <dokk:vocab:library:>
|
|
140
|
+ |
|
|
141
|
+ |
SELECT DISTINCT ?id ?title
|
|
142
|
+ |
WHERE {
|
|
143
|
+ |
?id a library:Journal;
|
|
144
|
+ |
library:title ?title
|
|
145
|
+ |
}
|
|
146
|
+ |
ORDER BY ?title
|
|
147
|
+ |
""")['results']['bindings']
|
|
148
|
+ |
|
137
|
149
|
|
# Retrieve filters selected by the user
|
138
|
150
|
|
filters_author = []
|
|
151
|
+ |
filters_journal = []
|
139
|
152
|
|
filters_license = []
|
140
|
153
|
|
query_filters = ''
|
141
|
154
|
|
if request.method == 'POST':
|
142
|
155
|
|
filters_author = request.forms.getall('author')
|
|
156
|
+ |
filters_journal = request.forms.getall('journal')
|
143
|
157
|
|
filters_license = request.forms.getall('license')
|
144
|
158
|
|
|
145
|
159
|
|
if len(filters_author) > 0:
|
146
|
160
|
|
query_filters_author = ','.join([ '"'+i.replace('"', '\\"')+'"' for i in filters_author ])
|
147
|
161
|
|
query_filters += f'FILTER(?author IN ({query_filters_author}))'
|
148
|
162
|
|
|
|
163
|
+ |
if len(filters_journal) > 0:
|
|
164
|
+ |
query_filters_journal = ','.join([ '<'+i+'>' for i in filters_journal ])
|
|
165
|
+ |
query_filters += f'FILTER(?journal IN ({query_filters_journal}))'
|
|
166
|
+ |
|
149
|
167
|
|
if len(filters_license) > 0:
|
150
|
168
|
|
query_filters_license = ','.join([ '"'+i.replace('"', '\\"')+'"' for i in filters_license ])
|
151
|
169
|
|
query_filters += f'FILTER(?license_id IN ({query_filters_license}))'
|
154
|
172
|
|
PREFIX library: <dokk:vocab:library:>
|
155
|
173
|
|
PREFIX license: <dokk:vocab:license:>
|
156
|
174
|
|
|
157
|
|
- |
CONSTRUCT {{
|
158
|
|
- |
?item library:title ?title;
|
159
|
|
- |
library:author ?author ;
|
160
|
|
- |
license:licensed_under ?license .
|
161
|
|
- |
?license license:id ?license_id ;
|
162
|
|
- |
license:name ?license_name .
|
163
|
|
- |
}}
|
164
|
|
- |
WHERE {{
|
165
|
|
- |
?item library:title ?title ;
|
166
|
|
- |
library:author ?author ;
|
167
|
|
- |
license:licensed_under ?license .
|
|
175
|
+ |
DESCRIBE *
|
|
176
|
+ |
WHERE
|
|
177
|
+ |
{{
|
|
178
|
+ |
?item
|
|
179
|
+ |
a library:Item;
|
|
180
|
+ |
library:title ?title ;
|
|
181
|
+ |
library:author ?author .
|
|
182
|
+ |
|
|
183
|
+ |
OPTIONAL {{ ?item license:licensed_under ?license }}
|
168
|
184
|
|
|
169
|
185
|
|
OPTIONAL {{
|
170
|
|
- |
?license license:id ?license_id_optional ;
|
171
|
|
- |
license:name ?license_name_optional .
|
|
186
|
+ |
?item library:journal ?journal .
|
|
187
|
+ |
?journal
|
|
188
|
+ |
a library:Journal ;
|
|
189
|
+ |
library:title ?journal_title .
|
172
|
190
|
|
}}
|
173
|
191
|
|
|
174
|
|
- |
BIND(COALESCE(?license_id_optional, SUBSTR(STR(?license), 14)) AS ?license_id)
|
175
|
|
- |
BIND(COALESCE(?license_name_optional, SUBSTR(STR(?license), 14)) AS ?license_name)
|
176
|
|
- |
|
177
|
192
|
|
{query_filters}
|
178
|
193
|
|
}}
|
179
|
|
- |
ORDER BY UCASE(?title)
|
|
194
|
+ |
ORDER BY ?title
|
180
|
195
|
|
""",
|
181
|
196
|
|
{
|
182
|
197
|
|
'@context': {
|
|
198
|
+ |
'blob': 'dokk:vocab:blob:',
|
183
|
199
|
|
'library': 'dokk:vocab:library:',
|
184
|
200
|
|
'license': 'dokk:vocab:license:',
|
185
|
201
|
|
'library:author': { '@container': '@set' },
|
186
|
202
|
|
'license:licensed_under': { '@container': '@set' }
|
187
|
203
|
|
},
|
188
|
|
- |
'library:title': {}
|
|
204
|
+ |
'@type': 'library:Item'
|
189
|
205
|
|
})
|
190
|
206
|
|
|
191
|
|
- |
return template('library/index.html', authors=authors, licenses=licenses, items=items,
|
192
|
|
- |
filters_author=filters_author, filters_license=filters_license)
|
|
207
|
+ |
return template('library/index.html', authors=authors, licenses=licenses,
|
|
208
|
+ |
journals=journals, items=items,
|
|
209
|
+ |
filters_author=filters_author,
|
|
210
|
+ |
filters_journal=filters_journal,
|
|
211
|
+ |
filters_license=filters_license)
|
193
|
212
|
|
|
194
|
213
|
|
@bottle.get('/library/<item_id>', name='library_item')
|
195
|
214
|
|
def library_item(item_id):
|
197
|
216
|
|
Show a single item in the library.
|
198
|
217
|
|
"""
|
199
|
218
|
|
|
200
|
|
- |
try:
|
201
|
|
- |
with open(f'../library_txt/{item_id}.txt', 'r') as file:
|
202
|
|
- |
item_plaintext = file.read()
|
203
|
|
- |
except:
|
204
|
|
- |
item_plaintext = ''
|
205
|
|
- |
|
206
|
219
|
|
data = query(f"""
|
|
220
|
+ |
PREFIX blob: <dokk:vocab:blob:>
|
207
|
221
|
|
PREFIX library: <dokk:vocab:library:>
|
208
|
222
|
|
PREFIX license: <dokk:vocab:license:>
|
209
|
223
|
|
|
210
|
|
- |
CONSTRUCT {{
|
211
|
|
- |
?item library:title ?title ;
|
212
|
|
- |
library:author ?author ;
|
213
|
|
- |
license:licensed_under ?license .
|
214
|
|
- |
|
215
|
|
- |
?license license:id ?license_id ;
|
216
|
|
- |
license:name ?license_name .
|
217
|
|
- |
}}
|
218
|
|
- |
WHERE {{
|
219
|
|
- |
?item
|
220
|
|
- |
library:title ?title ;
|
221
|
|
- |
library:author ?author ;
|
222
|
|
- |
license:licensed_under ?license .
|
223
|
|
- |
|
224
|
|
- |
FILTER (?item = <dokk:{item_id}>)
|
|
224
|
+ |
DESCRIBE ?item ?license ?blob ?journal
|
|
225
|
+ |
WHERE
|
|
226
|
+ |
{{
|
|
227
|
+ |
?item a library:Item ;
|
|
228
|
+ |
blob:at ?blob .
|
225
|
229
|
|
|
226
|
|
- |
OPTIONAL {{
|
227
|
|
- |
?license license:id ?license_id_optional ;
|
228
|
|
- |
license:name ?license_name_optional .
|
229
|
|
- |
}}
|
|
230
|
+ |
FILTER(?item = <dokk:{item_id}>)
|
230
|
231
|
|
|
231
|
|
- |
BIND(COALESCE(?license_id_optional, SUBSTR(STR(?license), 14)) AS ?license_id)
|
232
|
|
- |
BIND(COALESCE(?license_name_optional, SUBSTR(STR(?license), 14)) AS ?license_name)
|
|
232
|
+ |
OPTIONAL {{ ?item license:licensed_under ?license }}
|
|
233
|
+ |
OPTIONAL {{ ?item library:journal ?journal }}
|
233
|
234
|
|
}}
|
234
|
235
|
|
""",
|
235
|
236
|
|
{
|
236
|
237
|
|
"@context": {
|
|
238
|
+ |
"blob": "dokk:vocab:blob:",
|
237
|
239
|
|
"library": "dokk:vocab:library:",
|
238
|
240
|
|
"license": "dokk:vocab:license:",
|
239
|
241
|
|
"library:author": { "@container": "@set" },
|
240
|
242
|
|
"license:licensed_under": { "@container": "@set" }
|
241
|
243
|
|
},
|
242
|
|
- |
"library:title": {}
|
|
244
|
+ |
"@type": "library:Item",
|
243
|
245
|
|
}
|
244
|
246
|
|
)["@graph"][0]
|
245
|
247
|
|
|
246
|
|
- |
return template('library/item.html', item_id=item_id, plaintext=item_plaintext, data=data)
|
|
248
|
+ |
return template('library/item.html', data=data)
|
247
|
249
|
|
|
248
|
250
|
|
@bottle.get('/license', name='license_list')
|
249
|
251
|
|
def license_list():
|