# canonrdf

> This library provides methods for canonicalising RDF.

Latest version **0.0.2** (published 2022-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install canonrdf
pnpm add canonrdf
yarn add canonrdf
bun add canonrdf
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2022-01-04 |
| First published | 2022-01-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 42.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | uvdsl |
| Maintainers | uvdsl |
| Keywords | RDF |

## Links

- npm: https://www.npmjs.com/package/canonrdf
- Repository: https://github.com/uvdsl/canonrdf
- Homepage: https://github.com/uvdsl/canonrdf#readme
- Issues: https://github.com/uvdsl/canonrdf/issues
- npm.io page: https://npm.io/package/canonrdf

## Dependencies (2)

- [n3](https://npm.io/package/n3.md) ^1.12.2
- [crypto](https://npm.io/package/crypto.md) ^1.0.1

## Recent versions

- 0.0.2 (latest) — 2022-01-04
- 0.0.1 — 2022-01-04

## README

# CanonRDF: Canonicalising RDF Graphs

This is a very simple implementation of the algorithms of Aidan Hogan, presented in [1].

The original implementation was done in Java [2].
Other another implementation in Javascript was created by Ivan Herman [3] (which is great, just not written using Typescript which I wanted to use).

The goal of this Typescript implementation is to (a) to make me understand the algorithms and (b) to work in a browser for my projects.
First, I tried to convert Ivan's implementation to Typescript but encountered several data type mismatches. 
Since I did not feel comfortable messing around in code I do not understand, I ended up writing my own interpretation of the algorithm from scratch.

For the sake of interoperability, I would also like to
make this implemenation have the same output as the original Java implementation on the same inputs.
However, there are alot of open questions regarding an exact implementation, e.g. ordering of graphs, carry-over of hash bags, hashing tuples, etc.

---
### Installation
This package relies on [n3](https://github.com/rdfjs/N3.js) for handling RDF, currently using version `1.12.2`.
```
npm install n3@1.12.2 --save
npm install canonrdf --save
```
---
### Usage
```
const { isoCanonicalise } = require("canonrdf");
const { Store, Parser } = require("n3");

// the graph to relabel
const data = `
                _:a <p> _:b .
				_:b <p> _:c .
				_:c <p> _:a .
				_:x <p> _:y .
				_:y <p> _:z .
				_:z <p> _:x .
				<u> <p> <v> .
`
const store = new Store();
const parser = new Parser();
store.addQuads(parser.parse(data));

// show current labels
console.log(store._ids);

// use Hogan's algorithm
const relabeled = isoCanonicalise(store);

// print the new labels
console.log(relabeled._ids);

```


---
### References

[1] https://aidanhogan.com/docs/rdf-canonicalisation.pdf  
[2] https://github.com/aidhog/blabel/  
[3] https://github.com/iherman/canonical_rdf/

---
_Source: https://npm.io/package/canonrdf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
