Skip to content

Instantly share code, notes, and snippets.

View joeltg's full-sized avatar

Joel Gustafson joeltg

View GitHub Profile
@joeltg
joeltg / schema.schema.json
Last active September 28, 2020 05:57
Underlay APG Schema Schema
[
{
"id": "_:label",
"type": "label",
"key": "http://underlay.org/ns/label",
"value": "_:label-value"
},
{
"id": "_:label-value",
"type": "product",
@joeltg
joeltg / zip.ts
Created August 27, 2020 13:16
Zip two iterables
export const zip = <A, B>(
a: Iterable<A>,
b: Iterable<B>
): Iterable<[A, B]> => ({
[Symbol.iterator]() {
const iterA = a[Symbol.iterator]()
const iterB = b[Symbol.iterator]()
return {
next() {
const resultA = iterA.next()
@joeltg
joeltg / http.md
Last active May 28, 2020 19:22
Package Server HTTP API

Package Server HTTP API

A package server exposes a REST HTTP API for managing Underlay resources.

  • Assertions are arbitrary RDF datasets
  • Files are arbitrary byte arrays, with a single explicit MIME type and a known integer size in bytes
  • Packages are a kind of container analogous to a directory or a Git repository. Packages have metadata like schemas and provenance and contain assertions, files, and other packages.

Like all REST services, package servers implicitly distinguish between abstract resources and concrete representations. A resource is a conceptual target identified by a URL; a representation of a resource is a physical materialization in some known format of a version of that resource at a point in time. The REST API interfaces between the two, resolving requests for resources into concrete representations.

@joeltg
joeltg / ul-schema.ts
Last active May 20, 2020 00:14
Underlay schema validator
import * as t from "io-ts/lib/index"
import { isRight, Right } from "fp-ts/lib/Either"
const rdfType = t.literal("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
type Predicate = t.StringC | typeof rdfType
type ShapeExpr = t.Type<shapeExpr>
type ValueExpr = ShapeExpr | typeof Singular
type Cardinality = t.NumberC | t.LiteralC<1>
@joeltg
joeltg / package.shex
Created April 2, 2020 16:32
ShEx Schema for Underlay Packages
PREFIX u: <http://underlay.mit.edu/ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX ldp: <http://www.w3.org/ns/ldp#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX dcterms: <http://purl.org/dc/terms/>
start = bnode {
a [ u:Package ] ;
ldp:hasMemberRelation [ prov:hadMember ] ;
$_:resource ldp:membershipResource iri ;
@joeltg
joeltg / index.d.ts
Last active October 16, 2020 20:46
TypeScript module declarations for shex.js
declare module "@shexjs/parser" {
function construct(): Parser
interface Parser {
parse(shex: string): Schema
}
type Schema = {
"@context"?: "http://www.w3.org/ns/shex.jsonld"
type: "Schema"
@joeltg
joeltg / reducers.md
Last active March 9, 2020 20:10
Reducers

Background

Suppose we have a collection of RDF graphs (directed labelled multigraphs, possibly cyclic, nodes are identified by their label, node labels are URIs or RDF Literals, edge labels are URIs typically taken from one of a few well-known vocabularies) and let's call that structure a Package. Packages entail a natural "union" graph of their own where we merge the graphs by considering nodes with the same label to be the same node.

(background on the RDF data model as needed: primer, syntax, semantics)

We want people to be able to publish arbitrary graph data, but we also imagine people using packages to publish relatively structured data (like a relational table) and everything in-between (like a relational table annotated with arbitrary graph data). So we want to let packages optionally carry some metadata where they can define some schemas and list the nodes in the package that valida

@joeltg
joeltg / jsonld.d.ts
Last active April 17, 2019 17:37
TypeScript bindings for JSON-LD
type Container<T> = T | T[]
type RecursiveContainer<T> = T | RecursiveArray<T>
interface RecursiveArray<T> extends Array<RecursiveContainer<T>> {}
declare namespace JsonLd {
export type Graph = Container<Node>
export type Node = {
"@id"?: string
"@type"?: Container<string>
@joeltg
joeltg / elastic.json
Created April 15, 2019 13:35
ElasticSearch config for the Prior Art Archive
{
"mappings": {
"doc": {
"properties": {
"text": { "type": "text" },
"title": { "type": "text" },
"fileUrl": { "type": "keyword" },
"organizationId": { "type": "keyword" },
"uploadDate": { "type": "date" },
"publicationDate": { "type": "date" },
@joeltg
joeltg / tika-context.json
Last active April 15, 2019 05:10
Namespace prefix mappings for the RDF properties produced by Apache Tika, for use as a JSON-LD context
{
"dc": "http://purl.org/dc/elements/1.1/",
"dcterms": "http://purl.org/dc/terms/",
"Iptc4xmpCore": "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/",
"Iptc4xmpExt": "http://iptc.org/std/Iptc4xmpExt/2008-02-29/",
"plus": "http://ns.useplus.org/ldf/xmp/1.0/",
"cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties/",
"extended-properties": "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties/",
"photoshop": "http://ns.adobe.com/photoshop/1.0/",
"xmp": "http://ns.adobe.com/xap/1.0/",