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

Example 1

// 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(irl`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" .`,
  url`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(irl`https://site.example/#id1234`.href),
isNamed = rdfTermFactory.namedNode('http://xmlns.com/foaf/0.1/name'),
JamBa   = rdfTermFactory.literal('Jam Ba');

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

// derive a new dataset from semanticData
const dataset = semanticData.value.match(null, isNamed, JamBa );
for (const quad of dataset) {
  console.info(`<${quad.subject.value}>'s name is ${JamBa.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