Skip to content

Instantly share code, notes, and snippets.

View niklasl's full-sized avatar

Niklas Lindström niklasl

View GitHub Profile
@niklasl
niklasl / fact.ttl
Last active July 13, 2024 12:48
OWL-powered truth generation
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix : <http://example.org/ns#>
base <http://example.org/>
# TBox:
:Truth rdfs:subClassOf [ owl:onProperty rdf:reifies ; owl:allValuesFrom :Fact ] .
:Fact owl:equivalentClass [ owl:onProperty _:selfOfTypeFact ; owl:hasSelf true ] ,
@niklasl
niklasl / purchase-entailments-1.ttl
Last active July 13, 2024 19:52
Entailments on reifiers
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix : <http://example.org/ns#> .
@base <http://example.org/> .
<purchase1> a :Purchase ;
:date "2014-12-15"^^xsd:date ;
:seller <ComputerStore> ;
"""
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 + "+/"