Skip to content

Instantly share code, notes, and snippets.

Avatar

Pierre-Antoine Champin pchampin

View GitHub Profile
@pchampin
pchampin / example.ttl
Last active Jun 25, 2022
RDF-star "ocurrence" pattern vs. Schema.org "role" pattern
View example.ttl
@prefix s: <http://schema.org/>.
# simple (unqualified) statement
:dr_strangelove a s:Movie ;
s:actor :peter_sellers.
# RDF-star with "ocurrence" nodes
@pchampin
pchampin / pyld.py
Last active Apr 3, 2022
pyld command-line tool
View pyld.py
#!/usr/bin/env python
#
# Command-line JSON-LD processor based on PyLD
#
# Copyright © 2021-2022 Pierre-Antoine Champin <pierre-antoine@w3.org>
import argparse
import json
import sys
from urllib.parse import urljoin, urlsplit
@pchampin
pchampin / test_ref_opacity.py
Created Nov 15, 2020
Testing Referential Opacity in RDF* triple stores
View test_ref_opacity.py
#!/usr/bin/env python3
"""
This script checks different triple stores implementing RDF*,
to see how opaque/transparent are the terms used in embedded triples.
"""
from sys import argv, stderr
import base64
try:
import requests
except:
@pchampin
pchampin / gist:a7986233be1f158f277dbf94937a47d5
Created Sep 22, 2020
N3 axiomatization of builtin predicate `list:memberAt`
View gist:a7986233be1f158f277dbf94937a47d5
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix : <#>.
{ (?lst 1) :memberAt ?elt } <= { ?lst rdf:first ?elt. }.
{ (?lst ?i) :memberAt ?elt } <= { ?lst rdf:first ?elt. ?i math:equalTo 1. }.
{ (?lst ?i) :memberAt ?elt } <= { ?lst rdf:rest ?rest. (?rest ?j) :memberAt ?elt. (?j 1) math:sum ?i. }.
{ ((41) 1) :memberAt 41 } => { :TEST :PASS 1 }.
{ ((41) 1.0) :memberAt 41 } => { :TEST :PASS 2 }.
View sophia_experiment.rs
//! This is an experiment on how to get rid of lifetime parameters in
//! Sopghia's Graph and Dataset traits. It demonstrates the general idea
//! on a simplified version of Triple and Graph.
//!
//! Graph iterators no longer return Graph::Triple's,
//! they return a safe abstraction around it: GuardedTRiple<'a, Graph::Triple>.
//!
//! Graph::Triple itself can be one of several options:
//! * T (where T implements Triple)
//! * *const T (where T implements Triple)
@pchampin
pchampin / object_vs_tuple_comp.py
Last active Oct 20, 2016
Comparing performance of comparison operators between different implementation styles in Python
View object_vs_tuple_comp.py
from collections import namedtuple
from timeit import default_timer
from itertools import repeat
class Classic(object):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
@pchampin
pchampin / vsparqlstore.py
Last active Nov 5, 2020
A subclass of rdflib SPARQLUpdateStore with BNode support, for Virtuoso
View vsparqlstore.py
from rdflib import BNode, URIRef
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore, _node_to_sparql, _node_from_result, SPARQL_NS
from uuid import uuid4
def _virtuoso_compatible_generator():
return unicode(uuid4().int % 2**61)
# monkey patch BNode to make it virtuoso compatible
BNode.__new__.func_defaults = (None, _virtuoso_compatible_generator, 'b')
@pchampin
pchampin / IterablePromise.js
Last active Feb 8, 2017
An extension of JS Promises with a forEach method.
View IterablePromise.js
/* global Promise */
/**
* An IterablePromise is used to combine the ease of use of loops,
* with the power of Promises.
*
* Assume you want to apply an asynchronous function process(),
* returning a Promise, to each item of an array ``a``,
* but wait for each element to be processed before processing the next one.
* You would do it like this:
@pchampin
pchampin / httpgen.wsgi
Created Sep 25, 2014
HTTP response generator
View httpgen.wsgi
#!/usr/bin/env python
"""
This simple service is aimed at web application developers. It allows them to
specify in the URL the HTTP response they want to get, in order to test the
behaviour of client codes.
The PATH_INFO is the desired status code, optionnally followed by a custom
message, e.g.:
/200
View keybase.md

Keybase proof

I hereby claim:

  • I am pchampin on github.
  • I am pchampin (https://keybase.io/pchampin) on keybase.
  • I have a public key whose fingerprint is BCB1 45FD 5531 F653 C422 89F0 9D1E DAEE EF98 D438

To claim this, I am signing this object: