class SemanticData
extends GenericData

In-memory RDF dataset. Conformant with RDF 1.1, RDF-Star and the RDF/JS Dataset interface. Can be stored in Data containers.

Examples

Populating a dataset from files or programmatically, and querying the dataset:

// create an empty RDF dataset in memory
const semanticData = SemanticData.build();  // `semanticData.value` conforms to the `Dataset` interface

// add another dataset from an RDF/Turtle file
await semanticData.readFromUrl(url`https://site.example/rdf-dataset.ttl`);

// add another dataset from RDF/Turtle content
await semanticData.readFromText(
  `PREFIX foaf: <http://xmlns.com/foaf/0.1/>
   <#person1> a foaf:Person ;
     foaf:name "Jim Bo" .`,
  iri`https://site.example/rdf-dataset.ttl` // base IRI to resolve IRIs
);

await semanticData.readFromText(
  `BASE <https://site.example/rdf-dataset.ttl> # base IRI to resolve IRIs
   PREFIX foaf: <http://xmlns.com/foaf/0.1/>
   <#person2> a foaf:Person ;
     foaf:name "Jon Do" .`
);

// programmatically add RDF statements to semanticData
const
subject = rdfTermFactory.namedNode(iri`https://site.example/#id1234`.toString()),
isNamed = rdfTermFactory.namedNode('http://xmlns.com/foaf/0.1/name'),
JamBa   = rdfTermFactory.literal('Jam Ba');

semanticData.value.add(
  rdfTermFactory.quad(subject, isNamed, JamBa)
);

// read a derived dataset
const peopleNamedJamBa = semanticData.value.filter(
  statement => (
    iri`${statement.predicate.value}`.equals(iri`http://xmlns.com/foaf/0.1/name`) &&
    statement.object.value === JamBa.value
  )
);
for (const statement of peopleNamedJamBa) {
  console.info(`<${statement.subject.value}>'s name is ${statement.object.value}`);
}

Static Methods

Builder for semantic data values.

Properties

readonly
value

An in-memory RDF dataset that is conformant with the Dataset specification.

Methods

readFromText(
text,
baseIRI
)

Async RDF dataset reader.

Async RDF dataset reader.

RDF dataset serialiser.

Serialises the object to string for informational purposes.

See