Grapoi
Grapoi combines the concept of graph pointers and paths. The Grapoi
class is based on the PathList
class. A PathList
wraps multiple Path
objects in the ptrs
property and adds some convenience methods. PathList
and Grapoi
have almost the same interface, besides a stricter type interface for PathList
. That makes code written with PathList
slightly faster; Grapoi
code is, on the other hand, a bit more readable.
Interfaces
GraphPointer
A GraphPointer
refers to a term in a dataset and optional also a specific graph:
interface GraphPointer {
attribute Term term;
attribute Dataset dataset;
attribute Term? graph;
};
Path
A Path
is, in the simplest case, just a GraphPointer, but it can also describe a path over multiple edges in a dataset:
interface Path {
attribute Dataset dataset;
attribute Term? term;
attribute Term? graph;
attribute sequence<Edge> edges;
};
Edge
An Edge
describes one traversing step in a dataset with a quad and the start and end. The start and end are strings with the according property name of the quad, like subject
or predicate
:
interface Edge {
attribute Dataset dataset;
attribute Quad quad;
attribute DOMString start;
attribute DOMString end;
};
Example
The following example is based on the housemd dataset and shows the path and pointer functionality of Grapoi:
import housemd from 'housemd'
import rdf from 'rdf-ext'
const ns = {
schema: rdf.namespace('http://schema.org/')
}
const dataset = rdf.dataset(housemd({ factory: rdf }))
const house = rdf.grapoi({ dataset, term: 'Gregory' }).in().trim()
console.log('properties of the guy named Gregory:')
for (const quad of house.out().quads()) {
console.log(`\t${quad.predicate.value}: ${quad.object.value}`)
}
const nationalities = house
.out(ns.schema.knows)
.out(ns.schema.nationality)
.distinct()
console.log('nationalities of all known people:')
for (const value of nationalities.values) {
console.log(`\t${value}`)
}
JSDoc
PathList
Grapoi ⇐ A graph pointer object
Kind: global class
Extends: PathList
- Grapoi ⇐
PathList
- new Grapoi(dataset, factory, ptrs, term, terms, graph, graphs)
- .dataset ⇒
DatasetCore
|null
- .datasets ⇒
Array.<DatasetCore>
- .term ⇒
Term
|undefined
- .terms ⇒
Array.<Term>
- .value ⇒
String
|undefined
- .values ⇒
Array.<String>
- .addIn(predicates, [subjects], [callback]) ⇒
Grapoi
- .addList(predicates, [items]) ⇒
Grapoi
- .addOut(predicates, [objects], [callback]) ⇒
Grapoi
- .base(base) ⇒
Constructor
- .best(score) ⇒
Constructor
- .deleteIn(predicates, [subjects]) ⇒
Grapoi
- .deleteList(predicates) ⇒
Grapoi
- .deleteOut(predicates, [objects]) ⇒
Constructor
- .hasIn(predicates, [subjects]) ⇒
Constructor
- .hasOut(predicates, [objects]) ⇒
Constructor
- .in(predicates, [subjects]) ⇒
Constructor
- .out(predicates, [objects]) ⇒
Constructor
- .node(predicates) ⇒
Constructor
- .rebase(base) ⇒
Constructor
- .replace(replacement) ⇒
Constructor
- .score(score, [limit], [offset]) ⇒
Constructor
- .clone(args) ⇒
Constructor
- .distinct() ⇒
Constructor
- .execute(instruction) ⇒
Constructor
- .executeAll(instruction) ⇒
Constructor
- .filter(callback) ⇒
Constructor
- .isAny() ⇒
boolean
- .isList() ⇒
boolean
- .list() ⇒
Iterator.<Constructor>
|undefined
- .map(callback) ⇒
Array
- .quads() ⇒
Iterator.<Quad>
- .trim() ⇒
Constructor
new Grapoi(dataset, factory, ptrs, term, terms, graph, graphs)
Create a new instance
Param | Type | Description |
---|---|---|
dataset | DatasetCore | Dataset for the pointers |
factory | Environment | Factory for new quads |
ptrs | Array.<Path> | Use existing pointers |
term | Term | Term for the pointers |
terms | Array.<Term> | Terms for the pointers |
graph | Term | Graph for the pointers |
graphs | Array.<Term> | Graphs for graph pointers |
DatasetCore
| null
grapoi.dataset ⇒ Dataset of the pointer or null if there is no unique dataset.
Kind: instance property of Grapoi
Overrides: dataset
Returns: DatasetCore
| null
- Unique dataset or null
Array.<DatasetCore>
grapoi.datasets ⇒ An array of all datasets of all pointers.
Kind: instance property of Grapoi
Overrides: datasets
Returns: Array.<DatasetCore>
- Array of datasets.
Term
| undefined
grapoi.term ⇒ The term of the pointers if all pointers refer to a unique term.
Kind: instance property of Grapoi
Overrides: term
Returns: Term
| undefined
- Term of undefined
Array.<Term>
grapoi.terms ⇒ An array of all terms of all pointers.
Kind: instance property of Grapoi
Overrides: terms
Returns: Array.<Term>
- Array of all terms
String
| undefined
grapoi.value ⇒ The value of the pointers if all pointers refer to a unique term.
Kind: instance property of Grapoi
Overrides: value
Returns: String
| undefined
- Value or undefined
Array.<String>
grapoi.values ⇒ An array of all values of all pointers.
Kind: instance property of Grapoi
Overrides: values
Returns: Array.<String>
- Array of all values
Grapoi
grapoi.addIn(predicates, [subjects], [callback]) ⇒ Add quad(s) with the current terms as the object
Kind: instance method of Grapoi
Overrides: addIn
Returns: Grapoi
- this
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the quads |
[subjects] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Subjects of the quads |
[callback] | function | Function called for each subject as a pointer argument |
Grapoi
grapoi.addList(predicates, [items]) ⇒ Add list(s) with the given items
Kind: instance method of Grapoi
Overrides: addList
Returns: Grapoi
- this
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the lists |
[items] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | List items |
Grapoi
grapoi.addOut(predicates, [objects], [callback]) ⇒ Add quad(s) with the current terms as the subject
Kind: instance method of Grapoi
Overrides: addOut
Returns: Grapoi
- this
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the quads |
[objects] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Objects of the quads |
[callback] | function | Function called for each subject as a pointer argument |
Constructor
grapoi.base(base) ⇒ Base all terms with a relative IRI with the given base.
Kind: instance method of Grapoi
Returns: Constructor
- Instance with a single pointer with the term based
Param | Type | Description |
---|---|---|
base | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Base of the terms |
Constructor
grapoi.best(score) ⇒ Use the given score function on all pointers and return the pointer with the best score.
Kind: instance method of Grapoi
Returns: Constructor
- Instance with a single pointer with the best score
Param | Type | Description |
---|---|---|
score | function | Score function |
Grapoi
grapoi.deleteIn(predicates, [subjects]) ⇒ Delete quad(s) with the current terms as the object.
Kind: instance method of Grapoi
Overrides: deleteIn
Returns: Grapoi
- this
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the quads |
[subjects] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Subjects of the quads |
Grapoi
grapoi.deleteList(predicates) ⇒ Delete list(s).
Kind: instance method of Grapoi
Overrides: deleteList
Returns: Grapoi
- this
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the lists |
Constructor
grapoi.deleteOut(predicates, [objects]) ⇒ Delete quad(s) with the current terms as the subject.
Kind: instance method of Grapoi
Overrides: deleteOut
Returns: Constructor
- this
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the quads |
[objects] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Objects of the quads |
Constructor
grapoi.hasIn(predicates, [subjects]) ⇒ Filter the pointers based on matching quad(s) with the current terms as the object.
Kind: instance method of Grapoi
Overrides: hasIn
Returns: Constructor
- Instance that contains only the filtered pointers
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the quads |
[subjects] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Subjects of the quads |
Constructor
grapoi.hasOut(predicates, [objects]) ⇒ Filter the pointers based on matching quad(s) with the current terms as the subject.
Kind: instance method of Grapoi
Overrides: hasOut
Returns: Constructor
- Instance that contains only the filtered pointers
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the quads |
[objects] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Objects of the quads |
Constructor
grapoi.in(predicates, [subjects]) ⇒ Traverse the graph with the current terms as the object.
Kind: instance method of Grapoi
Overrides: in
Returns: Constructor
- Instance with pointers of the traversed target terms
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the quads |
[subjects] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Subjects of the quads |
Constructor
grapoi.out(predicates, [objects]) ⇒ Traverse the graph with the current terms as the subject.
Kind: instance method of Grapoi
Overrides: out
Returns: Constructor
- Instance with pointers of the traversed target terms
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Predicates of the quads |
[objects] | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Objects of the quads |
Constructor
grapoi.node(predicates) ⇒ Jump to random terms.
Kind: instance method of Grapoi
Overrides: node
Returns: Constructor
- Instance with pointers of the selected terms
Param | Type | Description |
---|---|---|
predicates | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Terms for the new pointers |
Constructor
grapoi.rebase(base) ⇒ Rebase all terms of the current pointers with a new base.
Kind: instance method of Grapoi
Returns: Constructor
- Instance with a single pointer with the new base as the term
Param | Type | Description |
---|---|---|
base | Grapoi | Array.<Grapoi> | Term | Array.<Term> | New base of the terms |
Constructor
grapoi.replace(replacement) ⇒ Replace all terms of the current pointers with another term.
Kind: instance method of Grapoi
Returns: Constructor
- Instance with a single pointer with the replacement as the term
Param | Type | Description |
---|---|---|
replacement | Grapoi | Array.<Grapoi> | Term | Array.<Term> | Term used as replacement |
Constructor
grapoi.score(score, [limit], [offset]) ⇒ Score the pointers and sort them by score value.
Kind: instance method of Grapoi
Returns: Constructor
- Instance of the scored pointers, sorted and sliced.
Param | Type | Description |
---|---|---|
score | function | @rdfjs/score compatible score function |
[limit] | Number | Limit for the result pointers |
[offset] | Number | Offset for the result pointers |
Constructor
grapoi.clone(args) ⇒ Create a new instance of the Constructor with a cloned list of pointers.
Kind: instance method of Grapoi
Overrides: clone
Returns: Constructor
- Cloned instance
Param | Description |
---|---|
args | Additional arguments for the constructor |
Constructor
grapoi.distinct() ⇒ Create a new instance with a unique set of pointers. The path of the pointers is trimmed.
Kind: instance method of Grapoi
Overrides: distinct
Returns: Constructor
- Instance with unique pointers
Constructor
grapoi.execute(instruction) ⇒ Executes a single instruction.
Kind: instance method of Grapoi
Overrides: execute
Returns: Constructor
- Instance with the result pointers.
Param | Description |
---|---|
instruction | The instruction to execute |
Constructor
grapoi.executeAll(instruction) ⇒ Executes an array of instructions.
Kind: instance method of Grapoi
Overrides: executeAll
Returns: Constructor
- Instance with the result pointers.
Param | Description |
---|---|
instruction | The instructions to execute |
Constructor
grapoi.filter(callback) ⇒ Filter the pointers based on the result of the given callback function.
Kind: instance method of Grapoi
Overrides: filter
Returns: Constructor
- Instance with the filtered pointers.
Param |
---|
callback |
boolean
grapoi.isAny() ⇒ Check if any pointer is an any-pointer.
Kind: instance method of Grapoi
Overrides: isAny
Returns: boolean
- True if any any-pointer was found
boolean
grapoi.isList() ⇒ Check if there is only one pointer and whether that pointer is a list.
Kind: instance method of Grapoi
Overrides: isList
Returns: boolean
- True if the pointer is a list
Iterator.<Constructor>
| undefined
grapoi.list() ⇒ Create an iterator for the list if the instance is a list; otherwise, return undefined.
Kind: instance method of Grapoi
Overrides: list
Returns: Iterator.<Constructor>
| undefined
- Iterator or undefined
Array
grapoi.map(callback) ⇒ Map each pointer using the given callback function.
Kind: instance method of Grapoi
Overrides: map
Returns: Array
- Array of mapped results
Param |
---|
callback |
Iterator.<Quad>
grapoi.quads() ⇒ Create an iterator of all quads of all pointer paths.
Kind: instance method of Grapoi
Overrides: quads
Returns: Iterator.<Quad>
- Iterator for the quads
Constructor
grapoi.trim() ⇒ Trim the path of all pointers and create a new instance for the result.
Kind: instance method of Grapoi
Overrides: trim
Returns: Constructor
- Instance of the trimmed pointers
PathList
List of paths
Kind: global class
Properties
Name | Type | Description |
---|---|---|
ptrs | Array | All paths of this list |
- PathList
- new PathList(dataset, factory, ptrs, terms, graphs)
- .dataset ⇒
DatasetCore
|null
- .datasets ⇒
Array.<DatasetCore>
- .term ⇒
Term
|undefined
- .terms ⇒
Array.<Term>
- .value ⇒
String
|undefined
- .values ⇒
Array.<String>
- .addIn(predicates, subjects, [callback]) ⇒
PathList
- .addList(predicates, items) ⇒
PathList
- .addOut(predicates, objects, [callback]) ⇒
PathList
- .clone(args) ⇒
Constructor
- .deleteIn(predicates, subjects) ⇒
PathList
- .deleteList(predicates) ⇒
PathList
- .deleteOut(predicates, objects) ⇒
PathList
- .distinct() ⇒
Constructor
- .execute(instruction) ⇒
Constructor
- .executeAll(instruction) ⇒
Constructor
- .filter(callback) ⇒
Constructor
- .hasIn(predicates, subjects) ⇒
Constructor
- .hasOut(predicates, objects) ⇒
Constructor
- .in(predicates, subjects) ⇒
Constructor
- .isAny() ⇒
boolean
- .isList() ⇒
boolean
- .list() ⇒
Iterator.<Constructor>
|undefined
- .map(callback) ⇒
Array
- .node(terms) ⇒
Constructor
- .out(predicates, objects) ⇒
Constructor
- .quads() ⇒
Iterator.<Quad>
- .trim() ⇒
Constructor
new PathList(dataset, factory, ptrs, terms, graphs)
Create a new instance
Param | Type | Description |
---|---|---|
dataset | DatasetCore | Dataset for the pointers |
factory | Environment | Factory for new quads |
ptrs | Array.<Path> | Use existing pointers |
terms | Array.<Term> | Terms for the pointers |
graphs | Array.<Term> | Graphs for the pointers |
DatasetCore
| null
pathList.dataset ⇒ Dataset of the pointer or null if there is no unique dataset.
Kind: instance property of PathList
Returns: DatasetCore
| null
- Unique dataset or null
Array.<DatasetCore>
pathList.datasets ⇒ An array of all datasets of all pointers.
Kind: instance property of PathList
Returns: Array.<DatasetCore>
- Array of datasets.
Term
| undefined
pathList.term ⇒ The term of the pointers if all pointers refer to a unique term.
Kind: instance property of PathList
Returns: Term
| undefined
- Term of undefined
Array.<Term>
pathList.terms ⇒ An array of all terms of all pointers.
Kind: instance property of PathList
Returns: Array.<Term>
- Array of all terms
String
| undefined
pathList.value ⇒ The value of the pointers if all pointers refer to a unique term.
Kind: instance property of PathList
Returns: String
| undefined
- Value or undefined
Array.<String>
pathList.values ⇒ An array of all values of all pointers.
Kind: instance property of PathList
Returns: Array.<String>
- Array of all values
PathList
pathList.addIn(predicates, subjects, [callback]) ⇒ Add quads with the current terms as the object
Kind: instance method of PathList
Returns: PathList
- this
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the quads |
subjects | Array.<Term> | Subjects of the quads |
[callback] | function | Function called for each subject as a pointer argument |
PathList
pathList.addList(predicates, items) ⇒ Add lists with the given items
Kind: instance method of PathList
Returns: PathList
- this
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the lists |
items | Array.<Term> | List items |
PathList
pathList.addOut(predicates, objects, [callback]) ⇒ Add quads with the current terms as the subject
Kind: instance method of PathList
Returns: PathList
- this
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the quads |
objects | Array.<Term> | Objects of the quads |
[callback] | function | Function called for each subject as a pointer argument |
Constructor
pathList.clone(args) ⇒ Create a new instance of the Constructor with a cloned list of pointers.
Kind: instance method of PathList
Returns: Constructor
- Cloned instance
Param | Description |
---|---|
args | Additional arguments for the constructor |
PathList
pathList.deleteIn(predicates, subjects) ⇒ Delete quads with the current terms as the object.
Kind: instance method of PathList
Returns: PathList
- this
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the quads |
subjects | Array.<Term> | Subjects of the quads |
PathList
pathList.deleteList(predicates) ⇒ Delete lists.
Kind: instance method of PathList
Returns: PathList
- this
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the lists |
PathList
pathList.deleteOut(predicates, objects) ⇒ Delete quads with the current terms as the subject.
Kind: instance method of PathList
Returns: PathList
- this
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the quads |
objects | Array.<Term> | Objects of the quads |
Constructor
pathList.distinct() ⇒ Create a new instance with a unique set of pointers. The path of the pointers is trimmed.
Kind: instance method of PathList
Returns: Constructor
- Instance with unique pointers
Constructor
pathList.execute(instruction) ⇒ Executes a single instruction.
Kind: instance method of PathList
Returns: Constructor
- Instance with the result pointers.
Param | Description |
---|---|
instruction | The instruction to execute |
Constructor
pathList.executeAll(instruction) ⇒ Executes an array of instructions.
Kind: instance method of PathList
Returns: Constructor
- Instance with the result pointers.
Param | Description |
---|---|
instruction | The instructions to execute |
Constructor
pathList.filter(callback) ⇒ Filter the pointers based on the result of the given callback function.
Kind: instance method of PathList
Returns: Constructor
- Instance with the filtered pointers.
Param |
---|
callback |
Constructor
pathList.hasIn(predicates, subjects) ⇒ Filter the pointers based on matching quad(s) with the current terms as the object.
Kind: instance method of PathList
Returns: Constructor
- Instance that contains only the filtered pointers
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the quads |
subjects | Array.<Term> | Subjects of the quads |
Constructor
pathList.hasOut(predicates, objects) ⇒ Filter the pointers based on matching quad(s) with the current terms as the subject.
Kind: instance method of PathList
Returns: Constructor
- Instance that contains only the filtered pointers
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the quads |
objects | Array.<Term> | Objects of the quads |
Constructor
pathList.in(predicates, subjects) ⇒ Traverse the graph with the current terms as the object.
Kind: instance method of PathList
Returns: Constructor
- Instance with pointers of the traversed target terms
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the quads |
subjects | Array.<Term> | Subjects of the quads |
boolean
pathList.isAny() ⇒ Check if any pointer is an any-pointer.
Kind: instance method of PathList
Returns: boolean
- True if any any-pointer was found
boolean
pathList.isList() ⇒ Check if there is only one pointer and whether that pointer is a list.
Kind: instance method of PathList
Returns: boolean
- True if the pointer is a list
Iterator.<Constructor>
| undefined
pathList.list() ⇒ Create an iterator for the list if the instance is a list; otherwise, return undefined.
Kind: instance method of PathList
Returns: Iterator.<Constructor>
| undefined
- Iterator or undefined
Array
pathList.map(callback) ⇒ Map each pointer using the given callback function.
Kind: instance method of PathList
Returns: Array
- Array of mapped results
Param |
---|
callback |
Constructor
pathList.node(terms) ⇒ Create a new instance with pointers using the given terms.
Kind: instance method of PathList
Returns: Constructor
- Instance with pointers of the given terms
Param | Description |
---|---|
terms | Array of terms for the pointers |
Constructor
pathList.out(predicates, objects) ⇒ Traverse the graph with the current terms as the subject.
Kind: instance method of PathList
Returns: Constructor
- Instance with pointers of the traversed target terms
Param | Type | Description |
---|---|---|
predicates | Array.<Term> | Predicates of the quads |
objects | Array.<Term> | Objects of the quads |
Iterator.<Quad>
pathList.quads() ⇒ Create an iterator of all quads of all pointer paths.
Kind: instance method of PathList
Returns: Iterator.<Quad>
- Iterator for the quads
Constructor
pathList.trim() ⇒ Trim the path of all pointers and create a new instance for the result.
Kind: instance method of PathList
Returns: Constructor
- Instance of the trimmed pointers