Skip to content

Instantly share code, notes, and snippets.

View peterk's full-sized avatar

Peter Krantz peterk

View GitHub Profile
@peterk
peterk / hydrate.groovy
Created October 27, 2015 14:04
Map local authority records to libris URI:s
@Grab('com.github.albaker:GroovySparql:0.9.0')
import groovy.sparql.*
@Grab('commons-lang#commons-lang;2.4')
import org.apache.commons.lang.WordUtils
import groovy.json.StringEscapeUtils
// Tab separated file with ids and names to look up in Libris.
// Example line format:
<h1>Tools for Everyone</h1>
<p>
This session looks at two tools that help to manage public sector metadata:
</p>
<p>
Scribe: Peter K
</p>
<h1>Tools for Everyone</h1>
<p>
This session looks at two tools that help to manage public sector metadata:
</p>
<p>
Scribe: Peter K
</p>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select DISTINCT ?name ?title ?book
WHERE {
?book <http://purl.org/dc/elements/1.1/creator> ?creator .
?creator <http://dbpedia.org/property/deathYear> "1945" .
?book <http://purl.org/dc/elements/1.1/title> ?title .
# coding: utf-8
import unicodecsv as csv
import networkx as nx
csvdata = csv.reader(open('query_result.csv', 'rb'), delimiter=',', encoding='utf-8')
next(csvdata) #skip headers
graph=nx.DiGraph(label="swepub")
for row in csvdata:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select DISTINCT ?name ?title ?book
WHERE {
?book <http://purl.org/dc/elements/1.1/creator> ?creator .
?creator <http://dbpedia.org/property/deathYear> "1945" .
?book <http://purl.org/dc/elements/1.1/title> ?title .
?creator foaf:name ?name .
@peterk
peterk / styles.less
Created February 15, 2016 12:02
styles.less turtle
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed.
*
* If you are unfamiliar with LESS, you can read more about it here:
* http://www.lesscss.org
*/
ext_ip="10.0.0.1" # Change this value to your vultr IP
server "default" {
listen on $ext_ip port 80
}
types {
text/css css ;
text/html htm html ;
text/txt txt ;
image/gif gif ;
@peterk
peterk / suecia.py
Last active June 6, 2016 05:56
Draft script to prepare Suecia images for Wikimedia commons upload
import re
import requests
from lxml import html
from lxml.builder import E
from lxml.etree import tostring
url = "https://data.kb.se/datasets/2014/10/suecia/"
template = "{{Kungliga biblioteket image|libris-id=%s|url=%s}}"
def getmeta(libris_id):
<?xml version='1.0' encoding='utf-8'?>
<metadata>
<records>
<record>
<source>https://data.kb.se/datasets/2014/10/suecia/14818031%2C1.tif/</source>
<title>Skoklosters slott och sockenkyrka</title>
<filename>Suecia antiqua (SELIBR 14818031)-1</filename>
<Commons_filename>Suecia antiqua (SELIBR 14818031)-1</Commons_filename>
<description>Skoklosters slott och sockenkyrka by Dahlbergh, Erik, 1625-1703.</description>
<permissions>{{Kungliga biblioteket image|libris-id=14818031}}