Skip to content

Instantly share code, notes, and snippets.

@BruJu
Last active Dec 16, 2020
Embed
What would you like to do?
Graphy and match

Context : I had trouble to compare Graphy and WasmTree behaviour on match calls, so I tried to understand how Graphy works.

Graphy semmed like it used some cache or lazy matching, so I did some tests

const graphy_factory = require('@graphy/core.data.factory')

const dataset = require('@graphy/memory.dataset.fast')();

const m = dataset.match();

dataset.add(
    graphy_factory.quad(
        graphy_factory.namedNode("http://subject"),
        graphy_factory.namedNode("http://predicate"),
        graphy_factory.namedNode("http://object"),
        graphy_factory.defaultGraph()
    )
)

console.log(m.size)

let s = 0;
for (let quad of m) {
    console.log(quad)
    s += 1
}
console.log(s);

Output :

0
0

const graphy_factory = require('@graphy/core.data.factory')

const dataset = require('@graphy/memory.dataset.fast')();

dataset.add(
    graphy_factory.quad(
        graphy_factory.namedNode("http://subjectold"),
        graphy_factory.namedNode("http://predicate"),
        graphy_factory.namedNode("http://object"),
        graphy_factory.defaultGraph()
    )
)

const m = dataset.match();

dataset.add(
    graphy_factory.quad(
        graphy_factory.namedNode("http://subject"),
        graphy_factory.namedNode("http://predicate"),
        graphy_factory.namedNode("http://object"),
        graphy_factory.defaultGraph()
    )
)

console.log(m.size)

let s = 0;
for (let quad of m) {
    console.log(quad)
    s += 1
}
console.log(s);
console.log(m.size)

Output :

1
Quad {
  subject: NamedNode { value: 'http://subjectold' },
  predicate: NamedNode { value: 'http://predicate' },
  object: NamedNode { value: 'http://object' },
  graph: GenericTerm {} }
Quad {
  subject: NamedNode { value: 'http://subject' },
  predicate: NamedNode { value: 'http://predicate' },
  object: NamedNode { value: 'http://object' },
  graph: GenericTerm {} }
2
1
  • Graphy lazily match the requested quads
  • adding is weird

match specification : https://rdf.js.org/dataset-spec/#dfn-match

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment