Skip to content
Snippets Groups Projects
Commit 441ef80e authored by Georg Petz's avatar Georg Petz
Browse files

Initial commit

parents
Branches
No related tags found
No related merge requests found
LOD
%% Cell type:code id: tags:
``` python
import requests
import pandas as pd
from SPARQLWrapper import SPARQLWrapper, JSON
import json
```
%% Cell type:markdown id: tags:
Set the SPARQL-Endpoint:
* https://lod.onb.ac.at/sparql/anno for ANNO
* https://lod.onb.ac.at/sparql/akon for AKON
%% Cell type:code id: tags:
``` python
anno_lod_endpoint = "https://lod.onb.ac.at/sparql/anno"
```
%% Cell type:markdown id: tags:
Methods to query the endpoint and build the dataframe:
%% Cell type:code id: tags:
``` python
def get_sparql_result(service, query):
sparql = SPARQLWrapper(service)
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
return sparql.query()
def get_sparql_dataframe(service, query):
result = get_sparql_result(service, query)
processed_results = result.convert()
cols = processed_results['head']['vars']
out = []
for row in processed_results['results']['bindings']:
item = []
for c in cols:
item.append(row.get(c, {}).get('value'))
out.append(item)
return pd.DataFrame(out, columns=cols)
```
%% Cell type:markdown id: tags:
Select all newspapers and periodicals with subjectheading Statistik:
%% Cell type:code id: tags:
``` python
query = '''
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX edm: <http://www.europeana.eu/schemas/edm/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT ?title ?subjectURI ?manifest
WHERE {?subjectURI dc:subject <http://d-nb.info/gnd/4056995-0> .
?subjectURI dc:title ?title .
?subjectURI edm:isShownBy ?firstpage .
?subjectURI edm:rights <http://creativecommons.org/publicdomain/mark/1.0/> .
?firstpage dcterms:isReferencedBy ?manifest
}'''
```
%% Cell type:markdown id: tags:
Get list of IIIF Manifests URLs:
%% Cell type:code id: tags:
``` python
df = get_sparql_dataframe(anno_lod_endpoint, query)
manifests = list(df['manifest'])
manifests
```
%% Output
['http://iiif.onb.ac.at/presentation/ANNO/stm1875ag0001/manifest',
'http://iiif.onb.ac.at/presentation/ANNO/stm1876ag0001/manifest',
'http://iiif.onb.ac.at/presentation/ANNO/stm1877ag0001/manifest']
%% Cell type:markdown id: tags:
Function to create a SACHA Collection (https://iiif.onb.ac.at/api#_collectionspostjsonprocessor):
%% Cell type:code id: tags:
``` python
def create_collection(description, list_of_manifest_ids_or_ids):
j = {
"description": description,
"elements": list_of_manifest_ids_or_ids
}
creation_link = 'https://iiif.onb.ac.at/presentation/collection'
result = requests.post(creation_link, json=j)
if result.status_code == 201:
print('SUCCESS: Create collection {}'.format(result.json()['url']))
elif result.status_code == 400:
print('ERROR: Request error creating collection')
print(result.text)
elif result.status_code == 500:
print('ERROR: Server error creating collection')
print(result.text)
else:
print('ERROR: General error creating collection, HTTP status = {}'.format(result.status_code))
```
%% Cell type:markdown id: tags:
Create the SACHA Collection:
%% Cell type:code id: tags:
``` python
create_collection("newspaper with subject heading Statistik", manifests)
```
%% Output
SUCCESS: Create collection https://iiif.onb.ac.at/presentation/collection/8hIOHDd7hW
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment