forked from linkeddata/rdflib.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typescript rebase WIP linkeddata#355
- Loading branch information
Showing
29 changed files
with
2,677 additions
and
654 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
export default { | ||
/** | ||
* Class orders | ||
*/ | ||
const ClassOrder: { | ||
[id: string]: number; | ||
} = { | ||
'Literal': 1, | ||
'Collection': 3, | ||
'Graph': 4, | ||
'NamedNode': 5, | ||
'BlankNode': 6, | ||
'Variable': 7 | ||
} | ||
|
||
export default ClassOrder |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import BlankNode from './blank-node' | ||
import ClassOrder from './class-order' | ||
import Node from './node-internal' | ||
import { ValueType, Bindings, TFTerm, CollectionTermType, TermType } from './types'; | ||
|
||
export function isCollection<T>(value: T | TFTerm): value is Collection { | ||
return (value as Node).termType === 'Collection' | ||
} | ||
|
||
/** | ||
* A collection of other RDF nodes | ||
*/ | ||
export default class Collection extends Node { | ||
|
||
static termType: CollectionTermType; | ||
|
||
/** | ||
* The identifier for this collection | ||
*/ | ||
id: number; | ||
|
||
/** | ||
* The nodes in this collection | ||
*/ | ||
|
||
elements: Node[]; | ||
|
||
/** | ||
* Whether this collection is closed | ||
*/ | ||
closed: boolean; | ||
|
||
/** | ||
* Initializes this collection | ||
* @param initial The initial elements | ||
*/ | ||
constructor(initial?: ReadonlyArray<ValueType>) { | ||
super() | ||
this.termType = Collection.termType | ||
this.id = BlankNode.nextId++ | ||
this.elements = [] | ||
this.closed = false | ||
if (initial && initial.length > 0) { | ||
initial.forEach(element => { | ||
this.elements.push(Node.fromValue(element) as Node) | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Appends an element to this collection | ||
* @param element The new element | ||
*/ | ||
append (element: Node): number { | ||
return this.elements.push(element) | ||
} | ||
|
||
/** | ||
* Closes this collection | ||
*/ | ||
close (): boolean { | ||
this.closed = true | ||
return this.closed | ||
} | ||
|
||
/** | ||
* Removes the first element from the collection (and return it) | ||
*/ | ||
shift (): Node | undefined { | ||
return this.elements.shift() | ||
} | ||
|
||
/** | ||
* Gets a new Collection with the substituting bindings applied | ||
* @param bindings The bindings to substitute | ||
*/ | ||
substitute(bindings: Bindings): Collection { | ||
var elementsCopy = this.elements.map(function (ea) { | ||
ea.substitute(bindings) | ||
}) | ||
return new Collection(elementsCopy as []) | ||
} | ||
toNT () { | ||
return Collection.toNT(this) | ||
} | ||
static toNT (collection) { | ||
return BlankNode.NTAnonymousNodePrefix + collection.id | ||
} | ||
|
||
/** | ||
* Serializes the collection to a string. | ||
* Surounded by (parantheses) and seperated by spaces. | ||
*/ | ||
toString () { | ||
return '(' + this.elements.join(' ') + ')' | ||
} | ||
|
||
/** | ||
* Preprends the specified element to the colelction's front | ||
* @param element The element to preprend | ||
*/ | ||
unshift (element: Node): number { | ||
return this.elements.unshift(element) | ||
} | ||
} | ||
Collection.termType = TermType.Collection | ||
Collection.prototype.classOrder = ClassOrder['Collection'] | ||
Collection.prototype.compareTerm = BlankNode.prototype.compareTerm | ||
Collection.prototype.isVar = false |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Node from './node-internal' | ||
import { TFDefaultGraph } from './types'; | ||
|
||
export default class DefaultGraph extends Node implements TFDefaultGraph { | ||
value: '' | ||
|
||
constructor () { | ||
super() | ||
this.termType = 'DefaultGraph' | ||
this.value = '' | ||
} | ||
toCanonical () { | ||
return this.value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.