# rdf-isomorphic

> Determines if two RDF graphs are isomorphic

Latest version **2.0.1** (published 2025-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install rdf-isomorphic
pnpm add rdf-isomorphic
yarn add rdf-isomorphic
bun add rdf-isomorphic
```

## Health

**Score 50/100 (C)** — status: stable.

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

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2025-01-30 |
| First published | 2018-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 51 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Ruben Taelman |
| Maintainers | rubensworks |
| Keywords | rdf, graph, isomorphic, isomorphism, rdfjs, linked data |

## Links

- npm: https://www.npmjs.com/package/rdf-isomorphic
- Repository: https://github.com/rubensworks/rdf-isomorphic.js
- Homepage: https://github.com/rubensworks/rdf-isomorphic.js#readme
- Issues: https://github.com/rubensworks/rdf-isomorphic.js/issues
- Funding: https://github.com/sponsors/rubensworks/
- npm.io page: https://npm.io/package/rdf-isomorphic

## Dependencies (3)

- [rdf-terms](https://npm.io/package/rdf-terms.md) ^2.0.0
- [rdf-string](https://npm.io/package/rdf-string.md) ^2.0.0
- [imurmurhash](https://npm.io/package/imurmurhash.md) ^0.1.4

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2025-01-30
- 2.0.0 — 2025-01-08
- 1.3.1 — 2022-11-09
- 1.3.0 — 2021-08-11
- 1.2.1 — 2021-04-04
- 1.2.0 — 2020-09-15
- 1.1.0 — 2018-11-08
- 1.0.3 — 2018-11-02
- 1.0.2 — 2018-08-31
- 1.0.1 — 2018-08-31
- 1.0.0 — 2018-08-30

## README

# RDF Isomorphism

[![Build status](https://github.com/rubensworks/rdf-isomorphic.js/workflows/CI/badge.svg)](https://github.com/rubensworks/rdf-isomorphic.js/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/rubensworks/rdf-isomorphic.js/badge.svg?branch=master)](https://coveralls.io/github/rubensworks/rdf-isomorphic.js?branch=master)
[![npm version](https://badge.fury.io/js/rdf-isomorphic.svg)](https://www.npmjs.com/package/rdf-isomorphic)

Determines if two RDF graphs are [isomorphic](https://www.w3.org/TR/rdf11-concepts/#graph-isomorphism),
i.e., if two RDF graphs are equal while ignoring quad order
and ignoring non-equal blank node labels between the graphs.

This package is can be useful within unit/spec tests.

This library accepts [RDFJS](http://rdf.js.org/)-compliant quads.

## Usage

The following examples assume the following imports:

```javascript
import { DataFactory } from "rdf-data-factory"; // External library
import { isomorphic } from "rdf-isomorphic";

const factory = new DataFactory();
```

### Check if two graphs are isomorphic

```javascript
const graphA = [
  factory.quad(
    factory.blankNode('s1'),
    factory.namedNode('p'),
    factory.blankNode('o1'),
  ),
];
const graphB = [
  factory.quad(
    factory.blankNode('s2'),
    factory.namedNode('p'),
    factory.blankNode('o2'),
  ),
];
isomorphic(graphA, graphB); // Outputs true
```

### Check if two graphs are **not** isomorphic

```javascript
const graphA = [
  factory.quad(
    factory.blankNode('s1'),
    factory.namedNode('p1'),
    factory.blankNode('o1'),
  ),
];
const graphB = [
  factory.quad(
    factory.blankNode('s2'),
    factory.namedNode('p2'),
    factory.blankNode('o2'),
  ),
];
isomorphic(graphA, graphB); // Outputs false
```

### Check if two graphs with nested quads are isomorphic

```javascript
const graphA = [
  factory.quad(
    factory.quad(
      factory.blankNode('sInner'),
      factory.namedNode('pInner'),
      factory.blankNode('o1'),
    ),
    factory.namedNode('pOuter'),
    factory.namedNode('oOuter'),
  )
];
const graphB = [
  factory.quad(
    factory.quad(
      factory.blankNode('sInner'),
      factory.namedNode('pInner'),
      factory.blankNode('o2'),
    ),
    factory.namedNode('pOuter'),
    factory.namedNode('oOuter'),
  )
];
isomorphic(graphA, graphB); // Outputs true
```

## Algorithm

This algorithm is based on the [RDF isomorphism checker in RDF.rb](http://blog.datagraph.org/2010/03/rdf-isomorphism),
which in its turn is based on the algorithm described by [Jeremy Carrol](http://www.hpl.hp.com/techreports/2001/HPL-2001-293.pdf).

In summary, the algorithm generates a hash for each blank node based on the connected resources.
These hashes are then compared between the two given graphs, and a bijection is attempted to be created.
If no such bijection can be found, then the graphs are considered non-isomorphic.

The implementation of this package is inspired by the Ruby [RDF::Isomorphic](https://github.com/ruby-rdf/rdf-Isomorphic) gem.

The algorithm has been adapted to work this nested quads by [Ruben Taelman](http://rubensworks.net/).

## License
This software is written by [Ruben Taelman](http://rubensworks.net/).

This code is released under the [MIT license](http://opensource.org/licenses/MIT).

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