graphy.js

A collection of RDF libraries for JavaScript

View the Project on GitHub

« API / Data Factory

@graphy/core.data.factory

Primer

Contents


Accessibility

The following code block demonstrates three different ways to access this module.

// stand-alone
const factory = require('@graphy/core.data.factory');

// via the graphy 'super module'
const graphy = require('graphy');
const factory = graphy.core.data.factory;

// via inheritted methods on the graphy 'super module'
const graphy = require('graphy');
const factory = graphy;

Datatypes

The following section describes hinted formatting on ES primitives that are used throughout this document.

Numbers:

Strings:

Structs:

A ‘struct’ refers to an interface for a simple ES Object value such that value.constructor === Object. This is important because some methods may perform duck-typing on their arguments in order to deduce which overloaded variant to employ. The following section documents the definitions for these interfaces.

Hash Interfaces:

A ‘hash’ is a synonym of a HashMap; it refers to an object whose keys are arbitrarily decided by you, the user. The following section documents significance of the keys and expected values for hashes used by this library.


Functions:

factory.namedNode(iri: string)

factory.blankNode(...)

factory.defaultGraph()

factory.literal(contents: string[, datatype_or_lang: NamedNode | #string/language-tag])

factory.ephemeral()

factory.boolean(value: boolean | number | string)

factory.integer(value: #number/integer | string)

factory.double(value: number | string)

factory.decimal(value: number | string)

factory.number(value: number)

factory.date(date: Date)

factory.dateTime(dateTime: Date)

factory.quad(subject: Term, predicate: Term, object: Term, graph: Term)

factory.c1(term: #string/concise-term[, prefixes: #hash/prefix-mappings])

generator *factory.c3(triples: #hash/concise-triples[, prefixes: #hash/prefix-mappings])

generator *factory.c4(quads: #hash/concise-quads[, prefixes: #hash/prefix-mappings])

factory.fromTerm(term: AnyTerm)

factory.fromQuad(term: AnyQuad)

factory.comment(config: #config/comment)


Classes

abstract class GenericTerm implements AnyTerm, @RDFJS/Term

Properties:

Methods:

class NamedNode extends GenericTerm implements AnyTerm, @RDFJS/Term

A class that represents an RDF named node.

Properties implementing @RDFJS/NamedNode:

Properties:

Methods:

class BlankNode extends GenericTerm implements AnyTerm, @RDFJS/Term

A class that represents an RDF blank node.

Properties implementing @RDFJS/BlankNode:

Properties:

Methods:

Examples:

let kt_auto = factory.blankNode();
let kt_labeled = factory.blankNode('label');

kt_auto.isAnonymous;  // false
kt_label.isAnonymous;  // false

kt_auto.value;  // '_f4b39957_4619_459e_b954_a26f7b6da4a'
kt_label.value;  // 'label'

graphy.content.ttl.read('_:a <b> [] .', {
    data(y_quad) {
        y_quad.subject.isAnonymous;  // false
        y_quad.object.isAnonymous;  // true
    },
});

class EphemeralBlankNode extends BlankNode implements AnyTerm, @RDFJS/Term

A class that represents an anonymous RDF blank node with ephemeral qualities. Primarily used for writing.

Properties implementing @RDFJS/BlankNode:

Properties:

Methods:

Examples:

let kt_ephemeral = factory.ephemeral();

kt_ephemeral.isAnonymous;  // true
kt_ephemeral.isEphemeral;  // true

// changes everytime it is accessed
kt_ephemeral.value;  // '_66f0cc19_e551_4d82_8bf2_73329fb578b2'
kt_ephemeral.value;  // '_12ebb618_981b_45c9_a63b_a1e30170fcd1'
kt_ephemeral.value;  // '_4335c2d1_b7e2_4a43_ae81_a9f3a73e31ab'

// same applies to the verbose string
kt_ephemeral.verbose();  // '_:_82d116e8_352b_4ec3_8e3a_3b100a53b557'
kt_ephemeral.verbose();  // '_:_72b4a5ab_f4f0_494c_a432_c82b9d5aed50'
kt_ephemeral.verbose();  // '_:_1110a7e0_39fa_45ed_88c3_03912da0d93c'

// the terse string is the anonymous blank node token
kt_ephemeral.terse();  // '[]'

// will never equal itself
kt_ephemeral.equals(kt_ephemeral);  // false

class DefaultGraph extends GenericTerm implements AnyTerm, @RDFJS/Term

A class that represents an RDF default graph.

Properties implementing @RDFJS/DefaultGraph:

Properties:

Methods:

class Literal extends GenericTerm implements AnyTerm, @RDFJS/Term

A class that represents an RDF literal.

Properties implementing @RDFJS/Literal:

Properties:

Methods:

class Literal_Boolean extends Literal

A class that represents an RDF literal that is an xsd:boolean.

Properties:

Methods:

Examples:

let kt_true = factory.boolean(true);
kt_true = factory.boolean(1);
kt_true = factory.boolean('t');
kt_true = factory.boolean('true');
kt_true = factory.boolean('True');
kt_true = factory.boolean('TRUE');

let kt_false = factory.boolean(false);
kt_false = factory.boolean(0);
kt_false = factory.boolean('f');
kt_false = factory.boolean('false');
kt_false = factory.boolean('False');
kt_false = factory.boolean('FALSE');

kt_true.isolate();  // {termType:'Literal', value:'true', language:'', datatype:{termType:'NamedNode', value:'http://www.w3.org/2001/XMLSchema#boolean', }, }
kt_true.verbose();  // "true"^^<http://www.w3.org/2001/XMLSchema#boolean>
kt_true.terse();  // true
kt_true.isBoolean;  // true
kt_true.boolean;  // true
kt_true.value;  // true

class Literal_Integer extends Literal

A class that represents an RDF literal that is an xsd:integer.

Properties:

Methods:

Examples:

let yt_answer = factory.integer(42);
yt_answer.verbose();  // '"42"^^<http://www.w3.org/2001/XMLSchema#integer>'
yt_answer.isNumeric;  // true
yt_answer.isInteger;  // true
yt_answer.isDouble;  // undefined
yt_answer.number + 1;  // 43
yt_answer.value;  // '42'

factory.integer('12').number;  // 12
factory.integer(12.1);  // throws an Error: Number is not an integer: 12.1
factory.integer('12.1');  // throws an Error: Invalid integer string: 12.1

class Literal_Decimal extends Literal

A class that represents an RDF literal that is an xsd:decimal.

Properties:

Methods:

class Literal_Double extends Literal

A class that represents an RDF literal that is an xsd:double.

Properties:

Methods:

Examples:

let yt_pi = factory.double(Math.PI);
yt_pi.value;  // '3.141592653589793'
yt_pi.isolate();  // '{termType:'Literal', value:'3.141592653589793', language:'', datatype:{termType:'NamedNode', value:'http://www.w3.org/2001/XMLSchema#double', }, }'
yt_pi.verbose();  // '"3.141592653589793"^^<http://www.w3.org/2001/XMLSchema#double>'
yt_pi.terse();  // '"3.141592653589793"^^<http://www.w3.org/2001/XMLSchema#double>'
yt_pi.isNumeric;  // true
yt_pi.isDouble;  // true
yt_pi.isInteger;  // undefined
yt_pi.number * 2;  // 6.283185307179586

graphy.content.ttl.read('<http://ex.org/unit-circle> <http://ex.org/area> 3.141592653589793 .', {
    data(y_quad) {
        y_quad.object.value;  // '3.141592653589793'
        y_quad.object.number;  // 3.141592653589793
        y_quad.object.datatype.value;  // 'http://www.w3.org/2001/XMLSchema#double'
    },
});

class Literal_PositiveInfinity extends Literal_Double

A class that represents an RDF literal that is positive infinity, which is of type xsd:double.

Overriding properties:

Properties:

Methods:

Examples:

let yt_pos_inf = factory.double(Infinity);
yt_pos_inf.value;  // INF
yt_pos_inf.isolate();  // '{termType:'Literal', value:'INF', language:'', datatype:{termType:'NamedNode', value:'http://www.w3.org/2001/XMLSchema#double', }, }'
yt_pos_inf.verbose();  // '"INF"^^<http://www.w3.org/2001/XMLSchema#double>'
yt_pos_inf.terse();  // '"INF"^^<http://www.w3.org/2001/XMLSchema#double>'
yt_pos_inf.isNumeric;  // true
yt_pos_inf.isDouble;  // true
yt_pos_inf.isInfinite;  // true
yt_pos_inf.number;  // Infinity

class Literal_NegativeInfinity extends Literal_Double

A class that represents an RDF literal that is negative infinity, which is of type xsd:double.

Overriding properties:

Properties:

Methods:

Examples:

let yt_neg_inf = factory.double(-Infinity);
yt_neg_inf.value;  // -INF
yt_neg_inf.isolate();  // '{termType:'Literal', value:'-INF', language:'', datatype:{termType:'NamedNode', value:'http://www.w3.org/2001/XMLSchema#double', }, }'
yt_neg_inf.verbose();  // '"-INF"^^<http://www.w3.org/2001/XMLSchema#double>'
yt_neg_inf.terse();  // '"-INF"^^<http://www.w3.org/2001/XMLSchema#double>'
yt_neg_inf.isNumeric;  // true
yt_neg_inf.isDouble;  // true
yt_neg_inf.isInfinite;  // true
yt_neg_inf.number;  // -Infinity

class Literal_NaN extends Literal_Double

A class that represents an RDF literal that is NaN, which is of type xsd:double.

Overriding properties:

Properties:

Methods:

Examples:

let yt_nan = factory.double(NaN);
yt_nan.value;  // NaN
yt_nan.isolate();  // '{termType:'Literal', value:'NaN', language:'', datatype:{termType:'NamedNode', value:'http://www.w3.org/2001/XMLSchema#double', }, }'
yt_nan.verbose();  // '"NaN"^^<http://www.w3.org/2001/XMLSchema#double>'
yt_nan.terse();  // '"NaN"^^<http://www.w3.org/2001/XMLSchema#double>'
yt_nan.isNumeric;  // true
yt_nan.isDouble;  // true
yt_nan.isNaN;  // true
yt_nan.number;  // NaN

class Quad implements @RDFJS/Quad

A class that represents an RDF quad.

Properties:

Methods:

Examples:

graphy.content.ttl.read('<http://ex.org/unit-circle> <http://ex.org/area> 3.141592653589793 .', {
    data(y_quad) {
        y_quad.isolate();  // {subject:{termType:'NamedNode', value:'http://ex.org/unit-circle', }, predicate:{termType:'NamedNode', value:'http://ex.org/area', }, object:{termType:'Literal', value:'3.141592653589793', language:'', datatype:{termType:'NamedNode', value:'http://www.w3.org/2001/XMLSchema#decimal', }, }, graph:{termType:'DefaultGraph', value:'', }, }
        y_quad.verbose();  // <http://ex.org/unit-circle> <http://ex.org/area> "3.141592653589793"^^<http://www.w3.org/2001/XMLSchema#decimal> .
        y_quad.terse();  // <http://ex.org/unit-circle> <http://ex.org/area> 3.141592653589793 .
        y_quad.terse({ex:'http://ex.org/'});  // ex:unit-circle ex:area 3.141592653589793 .
    },
});

Interfaces

interface AnyTerm

Any object with the given properties defined, including plain objects. By definition, any instance of an @RDFJS/Term or GenericTerm also meet these criteria.

interface AnyQuad

Any object with the given properties defined, including plain objects. By definition, any instance of an @RDFJS/Quad or Quad also meet these criteria.