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

Revised Roles and Patterns #24

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
164 changes: 129 additions & 35 deletions data-model.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/* Data Model Interfaces */
/* https://rdf.js.org/data-model-spec/ */

/* RDF Modes allow for future expansion into other modes, e.g., "easierRDF" */

/* RDF 1.1 */
export type RdfMode_11 = 'rdf-1.1';

/* RDF* (rdf-star) */
export type RdfMode_star = 'rdf-star';

/* Modes officially supported/allowed by RDFJS */
export type AllowedRdfMode = RdfMode_11 | RdfMode_star;
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we want to add generalized RDF here as well?
This was the original motivation for adding the BaseQuad.



/**
* Contains an Iri, RDF blank Node, RDF literal, variable name, default graph, or a quad
* @see NamedNode
Expand Down Expand Up @@ -58,7 +70,7 @@ export interface BlankNode {
/**
* An RDF literal, containing a string with an optional language tag and/or datatype.
*/
export interface Literal {
export interface Literal<Datatype extends Role.Datatype=Role.Datatype> {
/**
* Contains the constant "Literal".
*/
Expand All @@ -76,7 +88,7 @@ export interface Literal {
/**
* A NamedNode whose IRI represents the datatype of the literal.
*/
datatype: NamedNode;
datatype: Datatype;

/**
* @param other The term to compare with.
Expand Down Expand Up @@ -127,38 +139,98 @@ export interface DefaultGraph {
equals(other: Term | null | undefined): boolean;
}


/**
* The subject, which is a NamedNode, BlankNode or Variable.
* @see NamedNode
* @see BlankNode
* @see Variable
* Type to be unioned with term types for forming role-specific pattern types
*/
export type Quad_Subject = NamedNode | BlankNode | Quad | Variable;
export type TermPattern = Variable | null;


/**
* The predicate, which is a NamedNode or Variable.
* @see NamedNode
* @see Variable
* Unions of Term types for the various roles they play in 'plain' RDF 1.1 Data
*/
export type Quad_Predicate = NamedNode | Variable;
export namespace Role {
export type Subject<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = NamedNode | BlankNode | (RdfMode extends RdfMode_star? Quad: never);

export type Predicate<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = NamedNode;

export type Object<
RdfMode extends AllowedRdfMode=RdfMode_star,
LiteralDatatype extends Datatype=Datatype,
> = NamedNode | BlankNode | Literal<LiteralDatatype> | (RdfMode extends RdfMode_star? Quad: never);

export type Graph<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = DefaultGraph | NamedNode | BlankNode;

export type Datatype<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = NamedNode;
}


/**
* The object, which is a NamedNode, Literal, BlankNode or Variable.
* @see NamedNode
* @see Literal
* @see BlankNode
* @see Variable
* Unions of Term types for the various
*/
export type Quad_Object = NamedNode | Literal | BlankNode | Quad | Variable;
export namespace Pattern {
export type Subject<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = Role.Subject | TermPattern;

export type Predicate<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = Role.Predicate | TermPattern;

export type Object<
RdfMode extends AllowedRdfMode=RdfMode_star,
LiteralDatatype extends Datatype=Datatype,
> = Role.Object | TermPattern;

export type Graph<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = Role.Graph | TermPattern;

export type Datatype<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = Role.Datatype | TermPattern;
}


/**
* The named graph, which is a DefaultGraph, NamedNode, BlankNode or Variable.
* @see DefaultGraph
* @see NamedNode
* @see BlankNode
* @see Variable
* The subject, which is a NamedNode, BlankNode or Variable.
* @deprecated Consider using one of the following types instead: @see Role.Subject or @see Pattern.Subject
*/
export type Quad_Graph = DefaultGraph | NamedNode | BlankNode | Variable;
export type Quad_Subject<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = Role.Subject<RdfMode> | Variable;

/**
* The predicate, which is a NamedNode or Variable.
* @deprecated Consider using one of the following types instead: @see Role.Predicate or @see Pattern.Predicate
*/
export type Quad_Predicate<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = Role.Predicate<RdfMode> | Variable;

/**
* The object, which is a NamedNode, Literal, BlankNode or Variable.
* @deprecated Consider using one of the following types instead: @see Role.Object or @see Pattern.Object
*/
export type Quad_Object<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = Role.Object<RdfMode> | Variable;

/**
* The named graph, which is a DefaultGraph, NamedNode, BlankNode or Variable.
* @deprecated Consider using one of the following types instead: @see Role.Graph or @see Pattern.Graph
*/
export type Quad_Graph<
RdfMode extends AllowedRdfMode=RdfMode_star,
> = Role.Graph<RdfMode> | Variable;

/**
* An RDF quad, taking any Term in its positions, containing the subject, predicate, object and graph terms.
Expand All @@ -175,22 +247,18 @@ export interface BaseQuad {

/**
* The subject.
* @see Quad_Subject
*/
subject: Term;
/**
* The predicate.
* @see Quad_Predicate
*/
predicate: Term;
/**
* The object.
* @see Quad_Object
*/
object: Term;
/**
* The named graph.
* @see Quad_Graph
*/
graph: Term;

Expand All @@ -204,33 +272,59 @@ export interface BaseQuad {
/**
* An RDF quad, containing the subject, predicate, object and graph terms.
*/
export interface Quad extends BaseQuad {
export interface Quad<
RdfMode extends AllowedRdfMode=RdfMode_star,
Copy link
Contributor

Choose a reason for hiding this comment

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

By constraining to AllowedRdfMode you essentially close the path for 3rd party modes, contradicting (?) your comment about "easyRDF"

Copy link
Member

Choose a reason for hiding this comment

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

I would also be in favor of a mechanism that enables developers to add other modes.
The approach from @tpluscode seems to enable this, so perhaps a combination of both approaches could be applied?

LiteralDataype extends Role.Datatype=Role.Datatype<RdfMode>
> extends BaseQuad {
/**
* The subject.
* @see Quad_Subject
*/
subject: Quad_Subject;
subject: Role.Subject<RdfMode>;
/**
* The predicate.
* @see Quad_Predicate
*/
predicate: Quad_Predicate;
predicate: Role.Predicate<RdfMode>;
/**
* The object.
* @see Quad_Object
*/
object: Quad_Object;
object: Role.Object<RdfMode, LiteralDataype>;
/**
* The named graph.
* @see Quad_Graph
*/
graph: Quad_Graph;
graph: Role.Graph<RdfMode>;
}

/**
* An RDF quad, containing the subject, predicate, object and graph terms.
*/
export interface QuadPattern<
RdfMode extends AllowedRdfMode=RdfMode_star,
LiteralDataype extends Role.Datatype=Role.Datatype<RdfMode>
> {
/**
* @param other The term to compare with.
* @return True if and only if the argument is a) of the same type b) has all components equal.
* The subject.
* @see Quad_Subject
*/
equals(other: Term | null | undefined): boolean;
subject: Pattern.Subject<RdfMode>;
/**
* The predicate.
* @see Quad_Predicate
*/
predicate: Pattern.Predicate<RdfMode>;
/**
* The object.
* @see Quad_Object
*/
object: Pattern.Object<RdfMode, LiteralDataype>;
/**
* The named graph.
* @see Quad_Graph
*/
graph: Pattern.Graph<RdfMode>;
}

/**
Expand Down