Skip to content

Instantly share code, notes, and snippets.

@ljos
ljos / OBT-stemmer.sh
Last active August 29, 2015 14:17
OBT hjelpeskript
#!/usr/bin/env bash
input_file="${1:-/dev/stdin}"
sed '/^\s*$/d' "$input_file" \
| paste -d '\t\0' - - - \
| sed -e 's/\([^"]*\)$/\t\1/' \
-e 's,<word>\(.*\)</word>,\1,' \
-e 's/"<\(.*\)>"\t"\(.*\)"/\1\t\2/' \
| cut -f3 \
| sed 's/./\L\0/g'
@ljos
ljos / tailor.sh
Last active August 29, 2015 14:17 — forked from sinelaw/tailor.sh
#!/bin/bash -eu
LOG_FILE=$1
SB="stdbuf -i0 -oL"
shift
tput sc
$@ 2>&1 | $SB tee $LOG_FILE | $SB cut -c-$(tput cols) | $SB sed -u 's/\(.\)/\\\1/g' | $SB xargs -0 -d'\n' -iyosi -n1 bash -c 'tput rc;tput el; printf "\r%s" yosi'
EXIT_CODE=${PIPESTATUS[0]}
tput rc;tput el;printf "\r" # Delete the last printed line
exit $EXIT_CODE
@ljos
ljos / README.md
Created November 21, 2011 11:53
Overloading Timeplot.DefaultEventSource.loadXML to be able to take in SPARQL results and converting with an xslt document instead of the normal XML.

There are better ways of doing this, but because I don't understand javascript or Timeplot and had to finish fast I did it like this.

I overload the loadXML function of DefaultEventSource to take inn a SPARQL result XML document with the url to an xsl_url. It converts the sparql result with xslt to the format that Timeplot reads.

I didn't need to read XML as well.

You can use the following xslt to transform sparql results.. or write your own.

Code released under GPLv3

@ljos
ljos / transfor-ssb-data.xsl
Created December 2, 2011 22:20
Transforms xml-keys documents from SSB to RDF/XML (in a horrible way). / Transformerer SSB dokumenter til RDF/XML (på en forferdelig måte). Code released under GPLv3 / Koden er sluppet under GPLv3.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY ssbont "http://localhost/ssbont.owl#" >
<!ENTITY dbpedia "http://dbpedia.org/resource/">
]>
<xsl:stylesheet
@ljos
ljos / README.md
Created December 2, 2011 22:23
Using Timeplot to create a graph to show sparql results.

A small project using timeplot, joseki and xslt to create graphs over time. The rdfs used in the searches here are ones created in a xslt you can find as another gist. The code is meant to run on as a part of a joseki sparql endpoint. At least that is where we sent the queries.

Code released under GPLv3.

@ljos
ljos / c2j.py
Created February 9, 2013 13:00
from os import listdir
from os.path import join
from re import match, findall, search, M
from time import mktime, strptime
from tldextract import extract
from collections import defaultdict
from HTMLParser import HTMLParser
class FindAllAs(HTMLParser):
def __init__(self, siteURL):
@ljos
ljos / slack_munin.sh
Created December 22, 2015 15:03 — forked from anarchivist/slack_munin.sh
Slack notification script for Munin
#!/bin/bash
# Slack notification script for Munin
# Mark Matienzo (@anarchivist)
#
# To use:
# 1) Create a new incoming webhook for Slack
# 2) Edit the configuration variables that start with "SLACK_" below
# 3) Add the following to your munin configuration:
#
@ljos
ljos / atekst.py
Last active January 2, 2016 19:19
Program to transform the output from atekst to csv where we are only interested in articles that mention NAV in the article, but not in either the lead or the headline.
#! /usr/bin/env python3
import codecs
import csv
import re
import sys
import time
def parse_date(s):
# We assume that the date is always in the format '10.01.2014'.
@ljos
ljos / alter_keys.py
Last active September 5, 2018 01:06
Showing how to edit events from Quartz in Python
#! /usr/bin/python2.6
# I COULD ONLY GET IT TO RUN IN PYTHON2.6
# Running it in python2.7, installed from homebrew results in a segfault.
# I haven't been able to investigate why.
# Code translated from http://osxbook.com/book/bonus/chapter2/alterkeys/
# License: http://ljos.mit-license.org/
from Quartz import (
CGEventGetIntegerValueField, CGEventSetIntegerValueField,
kCGKeyboardEventKeycode,
kCGEventKeyDown, kCGEventKeyUp,
@ljos
ljos / no_nlp.org
Last active May 2, 2019 13:50
Introduction to NLP for Norwegian text

Introduction to NLP for Norwegian text

Norwegian is slightly strange

  • Two written forms
  • Idiosyncratic capitalization rules
  • Normativish grammar
  • Semantically driven

Recommended tools