Skip to content

Instantly share code, notes, and snippets.

@afs
afs / rules-spec.md
Last active July 8, 2025 04:56
Sketch of SHACL Rules doc

SHACL Rules

SHACL rules infer new triples. The input is a data graph and a shape graph with rules, the output is a graph of inferred triples that do not occur in the data graph.

Whether, and how, the output graph is added back into the data graph is a separate decision.

Notes

@@Datalog-ish then a collection of "run once rules easy for defaulting"

@afs
afs / sql-correlated-example.md
Last active June 20, 2025 14:37
SQL de-correlation example
@afs
afs / notes2.md
Last active July 7, 2025 13:57
Notes on SHACL Rules

SHACL Rules

SHACL rules infer new triples. The input is a data graph and a shapes graph which has rules; the output is a graph of inferred triples.

Whether, and how, the output graph is added back into the data graph is not part of the SHACL rules process. If being run to enrich the data graph, the process can be done inside a transaction updating the data graph.

The rule system is also capable of triple pattern matching - what datalog calls a "query" - where only necessary rules are run. (This is "backward chaining")

Once repeated application of rules is considered, there does not seem to be useful subsets of features. Fortunately, simple evaluation of (positive i.e. without negation) datalog is not a major piece of implementation. Run rules until no change; the implementation does not need to inspect the rule set structure. The literature has several better algorithms where implementation isn't partic

@afs
afs / config.ttl
Last active October 1, 2024 09:07
Fuseki configuration : RDFS + union default graph variants
PREFIX : <#>
PREFIX fuseki: <http://jena.apache.org/fuseki#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ja: <http://jena.hpl.hp.com/2005/11/Assembler#>
PREFIX tdb2: <http://jena.apache.org/2016/tdb#>
## RDFS+TDB2 Dataset
[] rdf:type fuseki:Server ;
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>SHACL-C Grammar</title>
<link rel="stylesheet" type="text/css" href="https://www.w3.org/StyleSheets/TR/base.css" />
<link rel="stylesheet" type="text/css" href="https://www.w3.org/2001/sw/DataAccess/rq23/local.css" />
</head>
<body>
<!-- GRAMMAR -->
@afs
afs / Dockerfile.build-env
Last active August 8, 2024 12:40
Jena build using docker 2024-08
## Build for Apache Jena
## maven with added dependencies for running Cypress and the UI part of the build.
## Run this container with the Jena mounted on /jena
FROM 'maven:3.9.8-eclipse-temurin-21-jammy' AS base
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
@prefix dash: <http://datashapes.org/dash#> .
## @prefix owl: <http://www.w3.org/2002/07/owl#> .
@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 tosh: <http://topbraid.org/tosh#> .
## @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
dash:ListNodeShape
a sh:NodeShape ;
public static void main(String...args) {
Model model = ModelFactory.createDefaultModel();
Resource subject1 = ResourceFactory.createResource("http://example/s1");
Resource subject2 = ResourceFactory.createResource("http://example/s2");
Property property = ResourceFactory.createProperty("http://example/p");
Long longValue = 6L;
model.addLiteral(subject1, property, ResourceFactory.createTypedLiteral(longValue.toString(), XSDDatatype.XSDlong));
model.addLiteral(subject2, property, longValue);
RDFWriter.source(model).lang(Lang.TTL).output(System.out);
}
@afs
afs / IRIProvider3986.java
Created August 6, 2022 15:03
IRIProvider3986 - Jena IRIProvider for iri4ld
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@afs
afs / BufferAlloc.java
Last active November 17, 2022 11:21
JavaCC Buffer location strategy
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.