diff --git a/README b/README index b940d60..723adb2 100644 --- a/README +++ b/README @@ -1,10 +1,3 @@ -# Extract plaintext from library PDF files. These texts are used in the library pages. - - cp -R pdf pdf_to_text - cd pdf_to_text - for file in *.pdf; do pdftotext -layout "$file"; done - rm -f *.pdf - # Database The tools used here are available for download at diff --git a/app.py b/app.py index 9ad73bb..231f070 100755 --- a/app.py +++ b/app.py @@ -108,7 +108,7 @@ def library(): Library index """ - # Get a list of authors for searching + # Get a list of authors for search filters authors = query(""" PREFIX library: @@ -119,7 +119,7 @@ def library(): ORDER BY ?name """)['results']['bindings'] - # Get a list of licenses for searching + # Get a list of licenses for search filters licenses = query(""" PREFIX library: PREFIX license: @@ -134,18 +134,36 @@ def library(): ORDER BY ?id """)['results']['bindings'] + # Get a list of journals for search filters + journals = query(""" + PREFIX library: + + SELECT DISTINCT ?id ?title + WHERE { + ?id a library:Journal; + library:title ?title + } + ORDER BY ?title + """)['results']['bindings'] + # Retrieve filters selected by the user filters_author = [] + filters_journal = [] filters_license = [] query_filters = '' if request.method == 'POST': filters_author = request.forms.getall('author') + filters_journal = request.forms.getall('journal') filters_license = request.forms.getall('license') if len(filters_author) > 0: query_filters_author = ','.join([ '"'+i.replace('"', '\\"')+'"' for i in filters_author ]) query_filters += f'FILTER(?author IN ({query_filters_author}))' + if len(filters_journal) > 0: + query_filters_journal = ','.join([ '<'+i+'>' for i in filters_journal ]) + query_filters += f'FILTER(?journal IN ({query_filters_journal}))' + if len(filters_license) > 0: query_filters_license = ','.join([ '"'+i.replace('"', '\\"')+'"' for i in filters_license ]) query_filters += f'FILTER(?license_id IN ({query_filters_license}))' @@ -154,42 +172,43 @@ def library(): PREFIX library: PREFIX license: - CONSTRUCT {{ - ?item library:title ?title; - library:author ?author ; - license:licensed_under ?license . - ?license license:id ?license_id ; - license:name ?license_name . - }} - WHERE {{ - ?item library:title ?title ; - library:author ?author ; - license:licensed_under ?license . + DESCRIBE * + WHERE + {{ + ?item + a library:Item; + library:title ?title ; + library:author ?author . + + OPTIONAL {{ ?item license:licensed_under ?license }} OPTIONAL {{ - ?license license:id ?license_id_optional ; - license:name ?license_name_optional . + ?item library:journal ?journal . + ?journal + a library:Journal ; + library:title ?journal_title . }} - BIND(COALESCE(?license_id_optional, SUBSTR(STR(?license), 14)) AS ?license_id) - BIND(COALESCE(?license_name_optional, SUBSTR(STR(?license), 14)) AS ?license_name) - {query_filters} }} - ORDER BY UCASE(?title) + ORDER BY ?title """, { '@context': { + 'blob': 'dokk:vocab:blob:', 'library': 'dokk:vocab:library:', 'license': 'dokk:vocab:license:', 'library:author': { '@container': '@set' }, 'license:licensed_under': { '@container': '@set' } }, - 'library:title': {} + '@type': 'library:Item' }) - return template('library/index.html', authors=authors, licenses=licenses, items=items, - filters_author=filters_author, filters_license=filters_license) + return template('library/index.html', authors=authors, licenses=licenses, + journals=journals, items=items, + filters_author=filters_author, + filters_journal=filters_journal, + filters_license=filters_license) @bottle.get('/library/', name='library_item') def library_item(item_id): @@ -197,53 +216,36 @@ def library_item(item_id): Show a single item in the library. """ - try: - with open(f'../library_txt/{item_id}.txt', 'r') as file: - item_plaintext = file.read() - except: - item_plaintext = '' - data = query(f""" + PREFIX blob: PREFIX library: PREFIX license: - CONSTRUCT {{ - ?item library:title ?title ; - library:author ?author ; - license:licensed_under ?license . - - ?license license:id ?license_id ; - license:name ?license_name . - }} - WHERE {{ - ?item - library:title ?title ; - library:author ?author ; - license:licensed_under ?license . - - FILTER (?item = ) + DESCRIBE ?item ?license ?blob ?journal + WHERE + {{ + ?item a library:Item ; + blob:at ?blob . - OPTIONAL {{ - ?license license:id ?license_id_optional ; - license:name ?license_name_optional . - }} + FILTER(?item = ) - BIND(COALESCE(?license_id_optional, SUBSTR(STR(?license), 14)) AS ?license_id) - BIND(COALESCE(?license_name_optional, SUBSTR(STR(?license), 14)) AS ?license_name) + OPTIONAL {{ ?item license:licensed_under ?license }} + OPTIONAL {{ ?item library:journal ?journal }} }} """, { "@context": { + "blob": "dokk:vocab:blob:", "library": "dokk:vocab:library:", "license": "dokk:vocab:license:", "library:author": { "@container": "@set" }, "license:licensed_under": { "@container": "@set" } }, - "library:title": {} + "@type": "library:Item", } )["@graph"][0] - return template('library/item.html', item_id=item_id, plaintext=item_plaintext, data=data) + return template('library/item.html', data=data) @bottle.get('/license', name='license_list') def license_list(): diff --git a/templates/library/index.html b/templates/library/index.html index 9f02c5f..e58ce9b 100644 --- a/templates/library/index.html +++ b/templates/library/index.html @@ -22,6 +22,16 @@

+ Journal: +
+ + +

+ License: