addBound

Add all the quads in pattern, with any variables replaced by the value given for them in the bindings map. Handling of unbound variables is determined by the argument unbound, as in #quadbound.

addBound(pattern: any, bindings: any, unbound: any)
Parameters
pattern (any)
bindings (any)
unbound (any)

mixin

Add all the properties (except "init") of each mixin. Add init, if it exists, to the the chain of things to call from the constructor.

Or, if it has a prototype, use that.

mixin(mixins: ...any)
Parameters
mixins (...any)

parse

Parse a string of trig/turtle/nquads using (and modifying) our current prefixes.

parse(text: string, options: object): Array
Parameters
text (string) What to parse
options (object) override what we pass to n3.Parser
Returns
Array: The quads resulting from the parse
Example
kb.parseTrig('x:s x:p 2.')
// =>
[]

quadMatch

Does the pattern quad "match" the data quad? Variables are simply treated as wildcards here, not real variables. Use unify() or solve() if you want real variable handling.

quadMatch(pattern: any, data: any)
Parameters
pattern (any)
data (any)

quadAsNQ

Convert a quad to a string representation in the NQuads format. Not called toNQuads because it's converting the argument, not "this".

quadAsNQ(q: any)
Parameters
q (any)

quadBound

Return a new quad, with any variables replace by the matching entry in bindings, or whatever unbound(term) returns if there's no matching entry. As special cases, 'pass' means just let them stay variables and 'skip' means return null instead of a quad. Default is to throw an error.

quadBound(q: any, bindings: any, unbound: any)
Parameters
q (any)
bindings (any)
unbound (any)

equate

Set the two arguments to be "equal". We'll hide all but one of the an equated set of terms. We reveal the alphabetically first one, just to be deterministic. (Maybe have a way to override this?)

equate(a: any, b: any)
Parameters
a (any)
b (any)

lit

Given some JS value, return a Literal representing it

See also describe() which can handle values that result in multiple triples.

lit(x: any)
Parameters
x (any)

matchAdded

Watch for the next added quad that matches this pattern, then resolve with that quad.

matchAdded(args: ...any)
Parameters
args (...any)

fields

returns the array ['subject', 'predicate', 'object', 'graph'] for all the times you need it.

fields

unify

Line up two quads, one with variables, and see if if there's a binding of the variables that would make the quads equal. This is a classic function in computer science.

We make the Unique Names Assumption for NamedNodes but not BlankNodes, which are basically treated as variables. This allows something like destructuring, but might not always be what you're expecting.

unify(pattern: Quad, data: Quad, bindings: object): boolean
Parameters
pattern (Quad) the quad with variables
data (Quad) the quad without variables
bindings (object) maps varName => value, when already unified
Returns
boolean: can the two quads be unified? If true, also adds the necessary binding to bindings

query

Almost the same as #solve, but calls kb.native() on the resulting values.

query(args: ...any)
Parameters
args (...any)

solve

Given a pattern of 1+ quads, generate all distinct bindings for the return-variables in the pattern, matching data in the kb.

Use #query if you want to receive native values (instead of RDF Literal objects).

solve(pattern: any, options: Object)
Parameters
pattern (any)
options (Object = {})
Name Description
options.bind Object Pre-set bindings for any variables in the pattern
options.select any Array or string of names of the variables to return values for, otherwise whichever ones don't start with underscore
options.returnArrays boolean Flag requesting that return values are arrays [1,2] instead of objects {someVar:1, otherVar:2}
options.limit int Max number of distinct results returned, in order determined by underlying store

fetch

Fetch content from URL and add the triples to the kb.

if options.graphName === true, then the url is used as the graphname. If it's truthy, its value is used. Otherwise, triples go in the default graph.

fetch(url: any, options: any)
Parameters
url (any)
options (any = {})

obtainHash

Return the hash of this keyType. If necessary, create it!

obtainHash(keyType: any)
Parameters
keyType (any)

keyType

return for example 'sg' if the subject and graphLabel are ruthy specifiedTerms. Variables are not specifiedTerms; there shouldn't be any variables in the store.

keyType(q: any)
Parameters
q (any)

key

Return a string uniquely identifying the named parts of q, in that order

partNames is like spo, gp, gsop, ...

This is probably a good place to focus for performance improvements.

key(partNames: any, q: any)
Parameters
partNames (any)
q (any)