rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
676 stars 127 forks source link

Store.add does not work as documented #323

Open nichtich opened 1 year ago

nichtich commented 1 year ago

Storing as documented:

#!/usr/bin/env node

const N3 = require('n3')
const { DataFactory } = N3
const { namedNode, literal, defaultGraph, quad } = DataFactory

const store = new N3.Store()
store.add(
  namedNode('http://ex.org/Pluto'),
  namedNode('http://ex.org/type'),
  namedNode('http://ex.org/Dog')
)
store.add(
  namedNode('http://ex.org/Mickey'),
  namedNode('http://ex.org/type'),
  namedNode('http://ex.org/Mouse')
)

// Retrieve all quads
for (const quad of store)
  console.log(quad);

console.log(store.size)

results in this output

Quad {
  id: '',
  _subject: DefaultGraph { id: '' },
  _predicate: DefaultGraph { id: '' },
  _object: DefaultGraph { id: '' },
  _graph: DefaultGraph { id: '' }
}
1

I don't understand the details of store.add vs. store.addQuad but the latter works:

store.addQuad(quad(
  namedNode('http://ex.org/Pluto'),
  namedNode('http://ex.org/type'),
  namedNode('http://ex.org/Dog')
))
store.addQuad(quad(
  namedNode('http://ex.org/Mickey'),
  namedNode('http://ex.org/type'),
  namedNode('http://ex.org/Mouse')
))