Convert an array of terms to a rdf:List.
The quads are ordered, so arrayToList()[0]?.subject
gives the list iri or undefined for an
empty list.
The array to convert.
An array with the first element the quads and the second the IRI of the list.
Convert an array of terms to a rdf:list.
The quads are ordered, so arrayToList()[0]?.subject
gives the list iri or undefined for an
empty list.
The array to convert.
Convert an array of terms to a rdf:Seq.
The array to convert.
An array with the first element the quads and the second the IRI of the seq.
Convert an array of terms to a rdf:list.
The quads are ordered, so arrayToList()[0]?.subject
gives the seq iri or undefined for an
empty seq.
The array to convert.
Retrieve the first quad of the list at {listEntry}
Retrieve the first quad of the list at {listIRI}
Retrieve the first term of the list at {listEntry}
Retrieve the first term of the list at {listEntry}
Retrieve the last quad of the list at {listEntry}
Retrieve the last quad of the list at {listIRI}
Retrieve the last term of the list at {listEntry}
Retrieve the last term of the list at {listIRI}
Convert a list to an array of terms
Convert a list from the point of {listEntry} to a Quad[].
Will stop if missing links in the list aren't present. Can handle circular lists.
Parses the numerical value of a rdfs:ContainerMembershipProperty predicate.
The value of the predicate or -1.
Creates a delta to add one or more elements to the sequence.
The store that contains the sequence.
The IRI of the sequence
The term or terms to push. Nested arrays aren't converted to nested sequences.
The delta method to use, uses replace by default.
Creates a delta to remove the first element in the sequence.
The store that contains the sequence.
The IRI of the sequence
The delta method to use, uses slice by default.
Convert a sequence to an array of terms
Generated using TypeDoc
js.rdf.dev/collections
Utilities for reading and manipulating different kinds of RDF collections (rdf:Seq, rdf:List)
Example
import rdf from "@ontologies/core"; import { arrayToList, arrayToSeq, firstTermOfList, lastTermOfList, firstTermOfSeq, lastTermOfSeq, listToArray, seqToArray, Store } from "@rdfdev/collections"; const myArray = ["one", 2, rdf.namedNode("https://three.example/")]; const myStore: Store; // This can be the LinkedRenderStore from link-lib or your own. // Converting an array to an rdf Sequence const [ seqData, seqIRI ] = arrayToSeq(myArray); myStore.addQuads(seqData); /** * The `seqData` would contain the following quads; * <seqIRI> a rdf:Seq . * rdf:_0 "one" . * rdf:_1 "2"^^http://www.w3.org/2001/XMLSchema#number . * rdf:_2 <https://three.example/> ; */ // Reading seqToArray(seqIRI); // [rdf.literal("one"), rdf.literal(2), rdf.namedNode("https://three.example/")] firstTermOfSeq(myStore, listIRI); // rdf.literal("one") lastTermOfSeq(myStore, listIRI); // rdf.namedNode("https://three.example/") const [ listData, listIRI ] = arrayToList(myArray); myStore.addQuads(listData); /** * The `seqData` would contain the following quads; * <listIRI> rdf:first "one" . * <listIRI> rdf:rest _:0 . * _:0 rdf:first "2"^^http://www.w3.org/2001/XMLSchema#number . * _:0 rdf:rest _:1 . * _:1 rdf:first <https://three.example/> ; * _:1 rdf:rest rdf:nil ; */ // Reading listToArray(listIRI); // [rdf.literal("one"), rdf.literal(2), rdf.namedNode("https://three.example/")] firstTermOfList(myStore, listIRI); // rdf.literal("one") lastTermOfList(myStore, listIRI); // rdf.namedNode("https://three.example/")
Getting started
Just install the package and its peer dependencies.
npm i @rdfdev/collections @ontologies/core @ontologies/ld @ontologies/rdf @ontologies/rdfs
yarn add @rdfdev/collections @ontologies/core @ontologies/ld @ontologies/rdf @ontologies/rdfs
Documentation
See the js.rdf.dev/collections documentation
See the complete js.rdf.dev documentation
Need help with linked data?
This package is brought to you by Ontola. We build production-grade linked data solutions and can help you from advice to building custom web services.