Skip to content

Instantly share code, notes, and snippets.

View niklasl's full-sized avatar

Niklas Lindström niklasl

View GitHub Profile
"""
A simple query language parser experiment.
"""
OPERATORS: dict[str, tuple[str | None, int, str | int]] = {
'and': ('AND', -1, 'AND'),
'or': ('OR', -1, 'AND'),
'not': ('NOT', 0, 1),
'^': ('INV', 0, 1),
'=': ('EQ', -1, 1),
## WORKS
</work/neverwhere-0> a :Work ;
#:identityType :Hub ;
:title [ a :Title ; :mainTitle "Neverwhere" ] ;
:contribution [ a :PrimaryContribution ;
:agent </person/Neil_Gaiman> ] ;
:language </language/eng> .
</work/neverwhere-1> a :Text ;
@niklasl
niklasl / rsync-to-unison.sh
Created October 28, 2017 21:02
Crude fallback when unison isn't available on your local machine. (Note that this method stores duplicates of the files of interest on the server.)
# Paths of interest
LOCALDIR=syncdir
HOST=user@example.org
LANDINGDIR=landingdir
TARGETDIR=syncdir
# Sync files from local device to the server landing dir
rsync -auv --delete $LOCALDIR/ $HOST:$LANDINGDIR
# Two-way-sync the landing dir with the target dir
@niklasl
niklasl / make_summary.py
Created February 3, 2017 14:33
Flat KBV vocabulary summary
from __future__ import unicode_literals, print_function
from rdflib import *
g = Graph().parse("https://id.kb.se/vocab/")
with open('select-summary.rq') as f:
select = f.read()
print('Term', 'Bases', 'Domain', 'Range', sep='\t')
for row in g.query(select):
@niklasl
niklasl / illustrated-text-class.ttl
Created October 7, 2016 12:44
Just an OWL sketch for possibly inferring some BibFrame details from other details...
prefix : <http://www.w3.org/2002/07/owl#>
prefix bf: <http://id.loc.gov/ontologies/bibframe/>
prefix kbv: <https://id.kb.se/vocab/>
prefix marcrel: <http://id.loc.gov/vocabulary/relators/>
kbv:IllustratedText a :Class;
:equivalentClass [
:intersectionOf (
bf:Text
[ a :Restriction;
@niklasl
niklasl / get-saogf-from-idkbse.py
Last active May 30, 2016 14:22
Get SAOGF from id.kb.se
#!/usr/bin/env python3
from urllib.parse import urljoin
from urllib.request import urlopen, Request
import json
import codecs
reader = codecs.getreader("utf-8")
def crawl(collection_url):
while True:
/**
* To level up your synesthesia, choose colors, apply on web pages and read
* some 100 000 words. Purportedly. :)
* http://www.theatlantic.com/technology/archive/2012/07/can-you-teach-yourself-synesthesia/259519/
*/
var charColorMap = {
a: 'darkred',
e: 'green',
s: 'blue',
import string
import math
CHARS = string.digits + string.lowercase
assert len(CHARS) == 36
CHARS += string.uppercase
assert len(CHARS) == 62
BASE64_CHARS = string.uppercase + string.lowercase + string.digits + "+/"
@niklasl
niklasl / schemaorg_to_jsonldcontext.py
Last active December 30, 2015 19:19
Generates a JSON-LD Context for Schema.org.
from rdflib import *
SDO = Namespace("http://schema.org/")
datatype_coerce_map = {
#SDO.Number: XSD.double,
SDO.Date: 'xsd:date',
SDO.DateTime: "xsd:dateTime",
}
<!DOCTYPE html>
<html>
<head>
<title>Using about with a table</title>
</head>
<body>
<table vocab="http://schema.org/">
<tr>
<th>Who</th>