-
Notifications
You must be signed in to change notification settings - Fork 11
/
Factory.js
74 lines (60 loc) · 1.58 KB
/
Factory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import BlankNode from './lib/BlankNode.js'
import DefaultGraph from './lib/DefaultGraph.js'
import fromTerm from './lib/fromTerm.js'
import Literal from './lib/Literal.js'
import NamedNode from './lib/NamedNode.js'
import Quad from './lib/Quad.js'
import Variable from './lib/Variable.js'
const langStringDatatype = new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString')
const stringDatatype = new NamedNode('http://www.w3.org/2001/XMLSchema#string')
class DataFactory {
constructor () {
this.init()
}
init () {
this._data = {
blankNodeCounter: 0,
defaultGraph: new DefaultGraph()
}
}
namedNode (value) {
return new NamedNode(value)
}
blankNode (value) {
value = value || ('b' + (++this._data.blankNodeCounter))
return new BlankNode(value)
}
literal (value, languageOrDatatype) {
if (typeof languageOrDatatype === 'string') {
return new Literal(value, languageOrDatatype, langStringDatatype)
} else {
return new Literal(value, '', languageOrDatatype || stringDatatype)
}
}
variable (value) {
return new Variable(value)
}
defaultGraph () {
return this._data.defaultGraph
}
quad (subject, predicate, object, graph = this.defaultGraph()) {
return new Quad(subject, predicate, object, graph)
}
fromTerm (original) {
return fromTerm(this, original)
}
fromQuad (original) {
return fromTerm(this, original)
}
}
DataFactory.exports = [
'blankNode',
'defaultGraph',
'fromQuad',
'fromTerm',
'literal',
'namedNode',
'quad',
'variable'
]
export default DataFactory