Skip to content

Instantly share code, notes, and snippets.

View BruJu's full-sized avatar
🐓

Julian Bruyat BruJu

🐓
View GitHub Profile
@BruJu
BruJu / tests_from_manifest.ts
Created March 21, 2022 06:57
Test from manifest
# Test parser from the W3C test suite manifest
describe("Tests from manifest", () => {
// const manifestUrl = "https://www.w3.org/2013/rdf-mt-tests/manifest.ttl";
const manifestContent = fs.readFileSync(path.join(__dirname, "w3c-test-manifest.ttl"), "utf8");
const manifestQuads = new n3.Parser().parse(manifestContent);
let tests = new TermMap<RDF.Quad_Subject, ManifestedTest>();
@BruJu
BruJu / OneStepBackward.ttl
Last active February 27, 2022 19:32
OneStepBackward
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sh: <http://www.w3.org/ns/shacl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix ex: <http://example.com/ns#>
prefix s: <http://schema.org/>
ex:OneStep a sh:NodeShape ;
@BruJu
BruJu / RDFAutomata.ts
Created January 25, 2022 14:29
RDFAutomata.ts
import * as RDF from '@rdfjs/types';
import TermMap from '@rdfjs/term-map';
import TermSet from '@rdfjs/term-set';
type EpsTransition = {
symbol: RDF.Term | null;
next: RDF.Term
};
@BruJu
BruJu / state.ts
Created January 18, 2022 12:48
Incremental state
// Incremental state for lang-turtle in my repository prec-demo
// It gives me serious headaches so I'm gisting it
import { Language, syntaxTree } from "@codemirror/language";
import { EditorState, StateField, Transaction } from "@codemirror/state";
import { SyntaxNode } from "@lezer/common";
import * as RDF from "@rdfjs/types";
import { DataFactory, Store } from 'n3';
function buildForest() {
@BruJu
BruJu / findAllOccurrencesOfTerms.ts
Created November 23, 2021 13:51
findAllOccurrencesOfTerms
/**
* Return all occurences of the given terms in a DStar Dataset
* @see https://github.com/BruJu/PREC
*/
function findAllOccurrencesOfTerms(graph: DStar, terms: RDF.Term[]): RDF.Quad[] {
return terms.flatMap(term => [
...graph.getQuads(term, null, null, $defaultGraph),
...graph.getQuads(null, term, null, $defaultGraph),
...graph.getQuads(null, null, term, $defaultGraph),
...graph.getRDFStarQuads().filter(q => QuadStar.containsTerm(q, term))
@BruJu
BruJu / two_legs.rs
Created October 28, 2021 14:37
two_legs.rs
// The feature that Rust needs
trait Animal { const LEGS: u32; }
fn walk_on_your_two_legs<A>(_animal: &A)
where A: Animal
// , A::LEGS == 2 :(
{
println!("I'm walking on my two legs")
}
'use strict';
/*
* This script enables to store multi nested quads in an N3.Store
* Usage:
* Add quads with addQuadsWithoutMultiNesting(store, quads)
* The store will contain the quads, but 2sd level nested quads will be replaced with a blank node
* When you have a quad for which you want the true version, use remakeMultiNesting(store, quads)
*
@BruJu
BruJu / pgoContext.ttl
Last active June 30, 2021 13:02
Property Graph Ontology Context
PREFIX prec: <http://bruy.at/prec#>
PREFIX pvar: <http://bruy.at/prec-trans#>
PREFIX pgo: <http://ii.uwb.edu.pl/pgo#>
PREFIX ex: <http://example.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
# A PREC Context to produce RDF graphs similar to the one produced by graphConv
# PREC: https://github.com/BruJu/PREC
# graphConv: https://github.com/domel/graphConv
@BruJu
BruJu / graph-reducer.js
Created May 14, 2021 17:05
Leftovers code from PREC
// === transformProperties
// TODO:
// if (asSet) {
// for (const bind of newB) {
// noList(store, bind.x);
// }
// }
@BruJu
BruJu / StoreAlterer.js
Created May 14, 2021 07:27
StoreAlterer.js
"use strict";
//! I was too lazy to learn how to use another Triple Pattern Matching and
//! Replacement library, let alone find one that is not async await heavy,
//! so I built one...
const DataFactory = require('n3').DataFactory;
const variable = DataFactory.variable;
/**