Skip to content

Instantly share code, notes, and snippets.

View pebbie's full-sized avatar

Peb Ruswono Aryan pebbie

View GitHub Profile
"""
author: Peb Ruswono Aryan
date: 20.02.2014
Simple Entity Resolution
read a text file (news) and resolve entities mentioned in the text
uses:
- external Part-of-Speech Tagger API (REST)
- Entity knowledge base over SPARQL with Regex filter
"""
file: html2wikitext.py
author: Peb Ruswono Aryan (28.02.2014)
desc:
script to convert html extracted by [http://github.com/petrabarus/perundangan](perundangan)
into wikitext used in http://hukum.pebbie.org
"""
import re
#!python
"""
game2048.py
bot to play 2048 game by http://gabrielecirulli.com/
as submission for https://www.hackerrank.com/contests/2048-game/challenges/2048
best score 157.2
"""
import copy
import random
import math
@pebbie
pebbie / dump_ckan.py
Created August 13, 2014 21:00
dump all data from ckan website
"""
call : dump_ckan.py <ckan_website>
ckan_website : e.g. http://data.ukp.go.id
author : Peb Ruswono Aryan
"""
from __future__ import print_function
import json
import os
@pebbie
pebbie / rdf2rdf.py
Created September 12, 2014 22:53
rdf-to-rdf format conversion in one line of python code
import sys, rdflib; print rdflib.Graph().parse(sys.argv[1], format=sys.argv[2] if len(sys.argv)>2 else "json-ld").serialize(format=sys.argv[3] if len(sys.argv)>3 else "n3") if len(sys.argv)>1 else "%s <input-file> [<input-format> <output-format>]" % sys.argv[0]
@pebbie
pebbie / hydra-client.py
Created September 15, 2014 16:22
an attempt to write a console for hydra
import sys
from rdflib import Graph, Namespace
from rdflib.namespace import RDF, RDFS
import requests
HYDRA = Namespace("http://www.w3.org/ns/hydra/core#")
class HydraOperation:
def __init__(self, subj, graph):
self.type = graph.value(subj, RDF.type)
@pebbie
pebbie / ldfstore.py
Created February 25, 2015 13:24
Wrapper of Linked Data Fragment as a Graph Store in RDFLib
from rdflib.store import Store
from rdflib import Graph, RDF, URIRef, Namespace
import urllib.parse as urlparse
def add_params(origUrl, paramsDict):
url_parts = list(urlparse.urlparse(origUrl))
query = dict(urlparse.parse_qsl(url_parts[4]))
query.update(dict([i for i in iter(paramsDict.items()) if i[1] is not None]))
url_parts[4] = urlparse.urlencode(query)
return urlparse.urlunparse(url_parts)
@pebbie
pebbie / rastore.py
Created March 1, 2015 22:40
Treat a NumPy array as a graph in RDFLib
"""
rastore - virtual RDF data store for rasters
a graph interface from a numpy array into RDF Data Cube
- shape (dimensions)
- element datatype
- elements as rdf list?
- slices? as structured naming of bnode or a slice object?
@pebbie
pebbie / abc.py
Created April 30, 2015 08:01
bottom-up a^n.b^n.c^n acceptor
import sys
class Rule:
def __init__(self, lhs, rhs):
self.lhs = lhs
self.rhs = rhs
def __repr__(self):
return "{0} ::== {1}".format(self.lhs, self.rhs)
tetangga = {
"1": {"R":"2","D":"3"},
"2": {"L":"1","D":"4"},
"3": {"R":"4","U":"1"},
"4": {"L":"3","U":"2"}
}
def getND(kode,arah):
if arah in tetangga[kode[-1]]:
return kode[:-1]+tetangga[kode[-1]][arah]