Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: problem with assumption that "quoted triples" are quads #35

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions data-model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @see DefaultGraph
* @see BaseQuad
*/
export type Term = NamedNode | BlankNode | Literal | Variable | DefaultGraph | BaseQuad;
export type Term = NamedNode | BlankNode | Literal | Variable | DefaultGraph | BaseQuad | BaseTriple;

/**
* Contains an IRI.
Expand Down Expand Up @@ -128,12 +128,12 @@ export interface DefaultGraph {
}

/**
* The subject, which is a NamedNode, BlankNode or Variable.
* The subject, which is a NamedNode, BlankNode, Variable, or a quoted triple.
* @see NamedNode
* @see BlankNode
* @see Variable
*/
export type Quad_Subject = NamedNode | BlankNode | Quad | Variable;
export type Quad_Subject = NamedNode | BlankNode | Triple | Variable;

/**
* The predicate, which is a NamedNode or Variable.
Expand All @@ -143,13 +143,13 @@ export type Quad_Subject = NamedNode | BlankNode | Quad | Variable;
export type Quad_Predicate = NamedNode | Variable;

/**
* The object, which is a NamedNode, Literal, BlankNode or Variable.
* The object, which is a NamedNode, Literal, BlankNode, Variable, or a quoted triple.
* @see NamedNode
* @see Literal
* @see BlankNode
* @see Variable
*/
export type Quad_Object = NamedNode | Literal | BlankNode | Quad | Variable;
export type Quad_Object = NamedNode | Literal | BlankNode | Triple | Variable;

/**
* The named graph, which is a DefaultGraph, NamedNode, BlankNode or Variable.
Expand Down Expand Up @@ -233,6 +233,13 @@ export interface Quad extends BaseQuad {
equals(other: Term | null | undefined): boolean;
}

export interface BaseTriple extends Omit<BaseQuad, 'graph' | 'termType'> {
termType: 'QuotedTriple';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
termType: 'QuotedTriple';
termType: 'Triple';

}
export interface Triple extends Omit<Quad, 'graph' | 'termType'> {
termType: 'QuotedTriple';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
termType: 'QuotedTriple';
termType: 'Triple';

}

/**
* A factory for instantiating RDF terms and quads.
*/
Expand Down Expand Up @@ -286,5 +293,5 @@ export interface DataFactory<OutQuad extends BaseQuad = Quad, InQuad extends Bas
* @return A new instance of Quad.
* @see Quad
*/
quad(subject: InQuad['subject'], predicate: InQuad['predicate'], object: InQuad['object'], graph?: InQuad['graph']): OutQuad;
quad(subject: InQuad['subject'] | InQuad, predicate: InQuad['predicate'], object: InQuad['object'] | InQuad, graph?: InQuad['graph']): OutQuad;
}
44 changes: 39 additions & 5 deletions rdf-js-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlankNode, DataFactory, Dataset, DatasetCore, DatasetCoreFactory, DatasetFactory, DefaultGraph, Literal,
NamedNode, Quad, BaseQuad, Sink, Source, Store, Stream, Term, Variable, Quad_Graph } from ".";
NamedNode, Quad, BaseQuad, Sink, Source, Store, Stream, Term, Variable, Quad_Graph, Triple, BaseTriple } from ".";
import { EventEmitter } from "events";

function test_terms() {
Expand Down Expand Up @@ -54,6 +54,32 @@ function test_terms() {
let defaultGraphEqual: boolean = defaultGraph.equals(someTerm);
defaultGraphEqual = defaultGraph.equals(null);
defaultGraphEqual = defaultGraph.equals(undefined);

const term: Term = <any> {};
let term2: Term | undefined
switch (term.termType) {
case 'Quad':
term2 = <BaseQuad>term;
break;
case 'QuotedTriple':

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case 'QuotedTriple':
case 'Triple':

term2 = <BaseTriple>term;
break;
case 'NamedNode':
term2 = <NamedNode>term;
break;
case 'Literal':
term2 = <Literal>term;
break;
case 'BlankNode':
term2 = <BlankNode>term;
break;
case 'Variable':
term2 = <Variable>term;
break;
case 'DefaultGraph':
term2 = <DefaultGraph>term;
break;
}
}

function test_quads() {
Expand Down Expand Up @@ -113,11 +139,15 @@ function test_datafactory_star() {
);

// Decompose the triple
if (quadBobAgeCertainty.subject.termType === 'Quad') {
const quadBobAge2: Quad = quadBobAgeCertainty.subject;
if (quadBobAgeCertainty.subject.termType === 'QuotedTriple') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (quadBobAgeCertainty.subject.termType === 'QuotedTriple') {
if (quadBobAgeCertainty.subject.termType === 'Triple') {

const quadBobAge2: Triple = quadBobAgeCertainty.subject;

const equalToSelf: boolean = quadBobAge2.equals(quadBobAge);
const notEqualToOtherType: boolean = quadBobAge2.equals(dataFactory.namedNode('ex:something:else'));

const dataset: DatasetCore = <any> {};
// @ts-expect-error: triple is not assignable to quad. It has no graph property
dataset.add(quadBobAge2);
}
}

Expand All @@ -137,11 +167,15 @@ function test_datafactory_star_basequad() {
);

// Decompose the triple
if (quadBobAgeCertainty.subject.termType === 'Quad') {
const quadBobAge2: BaseQuad = quadBobAgeCertainty.subject;
if (quadBobAgeCertainty.subject.termType === 'QuotedTriple') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (quadBobAgeCertainty.subject.termType === 'QuotedTriple') {
if (quadBobAgeCertainty.subject.termType === 'Triple') {

const quadBobAge2: BaseTriple = quadBobAgeCertainty.subject;

const equalToSelf: boolean = quadBobAge2.equals(quadBobAge);
const notEqualToOtherType: boolean = quadBobAge2.equals(dataFactory.namedNode('ex:something:else'));

const dataset: DatasetCore<BaseQuad> = <any> {};
// @ts-expect-error: triple is not assignable to quad. It has no graph property
dataset.add(quadBobAge2);
}
}

Expand Down