Skip to content

Instantly share code, notes, and snippets.

@BruJu
Last active December 16, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BruJu/b04c1eeea72b695daf97da3122fc34fd to your computer and use it in GitHub Desktop.
Save BruJu/b04c1eeea72b695daf97da3122fc34fd to your computer and use it in GitHub Desktop.
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