rdflib 2.2.21 → 2.2.22-0de51c50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/rdflib.min.js +1 -1
  2. package/dist/rdflib.min.js.LICENSE.txt +13 -1
  3. package/dist/rdflib.min.js.map +1 -1
  4. package/esm/blank-node.js +3 -27
  5. package/esm/collection.js +7 -29
  6. package/esm/default-graph.js +1 -15
  7. package/esm/empty.js +0 -13
  8. package/esm/factories/canonical-data-factory.js +5 -40
  9. package/esm/factories/extended-term-factory.js +0 -11
  10. package/esm/factories/factory-types.js +2 -1
  11. package/esm/factories/rdflib-data-factory.js +0 -8
  12. package/esm/fetcher.js +257 -481
  13. package/esm/formula.js +43 -142
  14. package/esm/index.js +19 -36
  15. package/esm/jsonldparser.js +20 -29
  16. package/esm/jsonparser.js +0 -7
  17. package/esm/lists.js +18 -33
  18. package/esm/literal.js +10 -42
  19. package/esm/n3parser.js +38 -351
  20. package/esm/named-node.js +8 -27
  21. package/esm/namespace.js +0 -1
  22. package/esm/node-internal.js +11 -24
  23. package/esm/node.js +1 -6
  24. package/esm/parse.js +10 -17
  25. package/esm/patch-parser.js +9 -29
  26. package/esm/query-to-sparql.js +0 -18
  27. package/esm/query.js +50 -133
  28. package/esm/rdfaparser.js +72 -210
  29. package/esm/rdfxmlparser.js +31 -128
  30. package/esm/serialize.js +8 -33
  31. package/esm/serializer.js +122 -286
  32. package/esm/sparql-to-query.js +44 -134
  33. package/esm/statement.js +8 -19
  34. package/esm/store.js +109 -280
  35. package/esm/types.js +3 -2
  36. package/esm/update-manager.js +110 -246
  37. package/esm/updates-via.js +0 -27
  38. package/esm/uri.js +6 -50
  39. package/esm/utils/default-graph-uri.js +1 -0
  40. package/esm/utils/termValue.js +0 -1
  41. package/esm/utils/terms.js +15 -16
  42. package/esm/utils-js.js +16 -57
  43. package/esm/utils.js +4 -15
  44. package/esm/variable.js +0 -20
  45. package/lib/blank-node.js +3 -28
  46. package/lib/class-order.js +0 -1
  47. package/lib/collection.js +7 -34
  48. package/lib/default-graph.js +0 -20
  49. package/lib/empty.js +0 -18
  50. package/lib/factories/canonical-data-factory.js +4 -51
  51. package/lib/factories/extended-term-factory.js +0 -18
  52. package/lib/factories/factory-types.d.ts +6 -6
  53. package/lib/factories/factory-types.js +0 -3
  54. package/lib/factories/rdflib-data-factory.js +0 -12
  55. package/lib/fetcher.d.ts +6 -6
  56. package/lib/fetcher.js +258 -470
  57. package/lib/formula.d.ts +1 -1
  58. package/lib/formula.js +43 -151
  59. package/lib/index.d.ts +1 -2
  60. package/lib/index.js +14 -82
  61. package/lib/jsonldparser.js +19 -33
  62. package/lib/jsonparser.js +0 -9
  63. package/lib/lists.js +14 -39
  64. package/lib/literal.js +10 -49
  65. package/lib/log.d.ts +0 -6
  66. package/lib/log.js +0 -1
  67. package/lib/n3parser.d.ts +1 -0
  68. package/lib/n3parser.js +39 -359
  69. package/lib/named-node.js +7 -35
  70. package/lib/namespace.js +0 -3
  71. package/lib/node-internal.js +11 -21
  72. package/lib/node.js +1 -11
  73. package/lib/parse.d.ts +1 -1
  74. package/lib/parse.js +8 -27
  75. package/lib/patch-parser.js +10 -33
  76. package/lib/query-to-sparql.js +0 -23
  77. package/lib/query.js +46 -152
  78. package/lib/rdfaparser.js +72 -220
  79. package/lib/rdfxmlparser.js +31 -132
  80. package/lib/serialize.d.ts +1 -1
  81. package/lib/serialize.js +8 -43
  82. package/lib/serializer.d.ts +1 -0
  83. package/lib/serializer.js +121 -297
  84. package/lib/sparql-to-query.js +42 -167
  85. package/lib/statement.js +8 -24
  86. package/lib/store.d.ts +2 -2
  87. package/lib/store.js +102 -282
  88. package/lib/tf-types.d.ts +4 -4
  89. package/lib/types.d.ts +8 -8
  90. package/lib/types.js +3 -3
  91. package/lib/update-manager.d.ts +2 -2
  92. package/lib/update-manager.js +110 -254
  93. package/lib/updates-via.js +0 -30
  94. package/lib/uri.js +5 -58
  95. package/lib/utils/default-graph-uri.js +1 -3
  96. package/lib/utils/termValue.js +0 -2
  97. package/lib/utils/terms.js +15 -34
  98. package/lib/utils-js.js +16 -80
  99. package/lib/utils.js +4 -21
  100. package/lib/variable.js +0 -25
  101. package/lib/xsd-internal.js +0 -3
  102. package/lib/xsd.js +0 -4
  103. package/package.json +40 -39
  104. package/src/fetcher.ts +2 -2
  105. package/src/index.ts +0 -2
  106. package/src/jsonldparser.js +13 -4
  107. package/src/n3parser.js +12 -4
  108. package/src/serialize.ts +4 -11
  109. package/src/serializer.js +24 -0
  110. package/src/update-manager.ts +18 -7
  111. package/changes.txt +0 -59
  112. package/esm/convert.js +0 -61
  113. package/lib/convert.d.ts +0 -2
  114. package/lib/convert.js +0 -77
  115. package/src/convert.js +0 -70
package/esm/named-node.js CHANGED
@@ -5,25 +5,20 @@ import _inherits from "@babel/runtime/helpers/inherits";
5
5
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
6
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
-
9
8
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
-
11
9
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
-
13
10
  import ClassOrder from './class-order';
14
11
  import Node from './node-internal';
15
12
  import { NamedNodeTermType } from './types';
16
13
  import { termValue } from './utils/termValue';
17
14
  import { isTerm } from './utils/terms';
15
+
18
16
  /**
19
17
  * A named (IRI) RDF node
20
18
  */
21
-
22
19
  var NamedNode = /*#__PURE__*/function (_Node) {
23
20
  _inherits(NamedNode, _Node);
24
-
25
21
  var _super = _createSuper(NamedNode);
26
-
27
22
  /**
28
23
  * Create a named (IRI) RDF Node
29
24
  * @constructor
@@ -31,35 +26,26 @@ var NamedNode = /*#__PURE__*/function (_Node) {
31
26
  */
32
27
  function NamedNode(iri) {
33
28
  var _this;
34
-
35
29
  _classCallCheck(this, NamedNode);
36
-
37
30
  _this = _super.call(this, termValue(iri));
38
-
39
31
  _defineProperty(_assertThisInitialized(_this), "termType", NamedNodeTermType);
40
-
41
32
  _defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.NamedNode);
42
-
43
33
  if (!_this.value) {
44
34
  throw new Error('Missing IRI for NamedNode');
45
35
  }
46
-
47
36
  if (!_this.value.includes(':')) {
48
37
  throw new Error('NamedNode IRI "' + iri + '" must be absolute.');
49
38
  }
50
-
51
39
  if (_this.value.includes(' ')) {
52
40
  var message = 'Error: NamedNode IRI "' + iri + '" must not contain unencoded spaces.';
53
41
  throw new Error(message);
54
42
  }
55
-
56
43
  return _this;
57
44
  }
45
+
58
46
  /**
59
47
  * Returns an $rdf node for the containing directory, ending in slash.
60
48
  */
61
-
62
-
63
49
  _createClass(NamedNode, [{
64
50
  key: "dir",
65
51
  value: function dir() {
@@ -69,11 +55,11 @@ var NamedNode = /*#__PURE__*/function (_Node) {
69
55
  if (q >= 0 && p < q + 2 || p < 0) return null;
70
56
  return new NamedNode(str.slice(0, p + 1));
71
57
  }
58
+
72
59
  /**
73
60
  * Returns an NN for the whole web site, ending in slash.
74
61
  * Contrast with the "origin" which does NOT have a trailing slash
75
62
  */
76
-
77
63
  }, {
78
64
  key: "site",
79
65
  value: function site() {
@@ -81,18 +67,17 @@ var NamedNode = /*#__PURE__*/function (_Node) {
81
67
  var p = str.indexOf('//');
82
68
  if (p < 0) throw new Error('This URI does not have a web site part (origin)');
83
69
  var q = str.indexOf('/', p + 2);
84
-
85
70
  if (q < 0) {
86
71
  return new NamedNode(str.slice(0) + '/'); // Add slash to a bare origin
87
72
  } else {
88
73
  return new NamedNode(str.slice(0, q + 1));
89
74
  }
90
75
  }
76
+
91
77
  /**
92
78
  * Creates the fetchable named node for the document.
93
79
  * Removes everything from the # anchor tag.
94
80
  */
95
-
96
81
  }, {
97
82
  key: "doc",
98
83
  value: function doc() {
@@ -102,24 +87,24 @@ var NamedNode = /*#__PURE__*/function (_Node) {
102
87
  return new NamedNode(this.value.split('#')[0]);
103
88
  }
104
89
  }
90
+
105
91
  /**
106
92
  * Returns the URI including <brackets>
107
93
  */
108
-
109
94
  }, {
110
95
  key: "toString",
111
96
  value: function toString() {
112
97
  return '<' + this.value + '>';
113
98
  }
114
- /** The local identifier with the document */
115
99
 
100
+ /** The local identifier with the document */
116
101
  }, {
117
102
  key: "id",
118
103
  value: function id() {
119
104
  return this.value.split('#')[1];
120
105
  }
121
- /** Alias for value, favored by Tim */
122
106
 
107
+ /** Alias for value, favored by Tim */
123
108
  }, {
124
109
  key: "uri",
125
110
  get: function get() {
@@ -128,27 +113,23 @@ var NamedNode = /*#__PURE__*/function (_Node) {
128
113
  set: function set(uri) {
129
114
  this.value = uri;
130
115
  }
116
+
131
117
  /**
132
118
  * Creates a named node from the specified input value
133
119
  * @param value - An input value
134
120
  */
135
-
136
121
  }], [{
137
122
  key: "fromValue",
138
123
  value: function fromValue(value) {
139
124
  if (typeof value === 'undefined' || value === null) {
140
125
  return value;
141
126
  }
142
-
143
127
  if (isTerm(value)) {
144
128
  return value;
145
129
  }
146
-
147
130
  return new NamedNode(value);
148
131
  }
149
132
  }]);
150
-
151
133
  return NamedNode;
152
134
  }(Node);
153
-
154
135
  export { NamedNode as default };
package/esm/namespace.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import RDFlibNamedNode from './named-node';
2
-
3
2
  /**
4
3
  * Gets a namespace for the specified namespace's URI
5
4
  * @param nsuri - The URI for the namespace
@@ -1,7 +1,6 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
-
5
4
  /**
6
5
  * The superclass of all RDF Statement objects, that is
7
6
  * NamedNode, Literal, BlankNode, etc.
@@ -12,6 +11,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
12
11
  */
13
12
  var Node = /*#__PURE__*/function () {
14
13
  // Specified in './node.ts' to prevent circular dependency
14
+
15
15
  // Specified in './node.ts' to prevent circular dependency
16
16
 
17
17
  /** The type of node */
@@ -19,133 +19,120 @@ var Node = /*#__PURE__*/function () {
19
19
  /** The class order for this node */
20
20
 
21
21
  /** The node's value */
22
+
22
23
  function Node(value) {
23
24
  _classCallCheck(this, Node);
24
-
25
25
  _defineProperty(this, "termType", void 0);
26
-
27
26
  _defineProperty(this, "classOrder", void 0);
28
-
29
27
  _defineProperty(this, "value", void 0);
30
-
31
28
  this.value = value;
32
29
  }
30
+
33
31
  /**
34
32
  * Creates the substituted node for this one, according to the specified bindings
35
33
  * @param bindings - Bindings of identifiers to nodes
36
34
  */
37
-
38
-
39
35
  _createClass(Node, [{
40
36
  key: "substitute",
41
37
  value: function substitute(bindings) {
42
38
  console.log('@@@ node substitute' + this);
43
39
  return this;
44
40
  }
41
+
45
42
  /**
46
43
  * Compares this node with another
47
44
  * @see {equals} to check if two nodes are equal
48
45
  * @param other - The other node
49
46
  */
50
-
51
47
  }, {
52
48
  key: "compareTerm",
53
49
  value: function compareTerm(other) {
54
50
  if (this.classOrder < other.classOrder) {
55
51
  return -1;
56
52
  }
57
-
58
53
  if (this.classOrder > other.classOrder) {
59
54
  return +1;
60
55
  }
61
-
62
56
  if (this.value < other.value) {
63
57
  return -1;
64
58
  }
65
-
66
59
  if (this.value > other.value) {
67
60
  return +1;
68
61
  }
69
-
70
62
  return 0;
71
63
  }
64
+
72
65
  /**
73
66
  * Compares whether the two nodes are equal
74
67
  * @param other The other node
75
68
  */
76
-
77
69
  }, {
78
70
  key: "equals",
79
71
  value: function equals(other) {
80
72
  if (!other) {
81
73
  return false;
82
74
  }
83
-
84
75
  return this.termType === other.termType && this.value === other.value;
85
76
  }
77
+
86
78
  /**
87
79
  * Creates a hash for this node
88
80
  * @deprecated use {rdfFactory.id} instead if possible
89
81
  */
90
-
91
82
  }, {
92
83
  key: "hashString",
93
84
  value: function hashString() {
94
85
  return this.toCanonical();
95
86
  }
87
+
96
88
  /**
97
89
  * Compares whether this node is the same as the other one
98
90
  * @param other - Another node
99
91
  */
100
-
101
92
  }, {
102
93
  key: "sameTerm",
103
94
  value: function sameTerm(other) {
104
95
  return this.equals(other);
105
96
  }
97
+
106
98
  /**
107
99
  * Creates a canonical string representation of this node
108
100
  */
109
-
110
101
  }, {
111
102
  key: "toCanonical",
112
103
  value: function toCanonical() {
113
104
  return this.toNT();
114
105
  }
106
+
115
107
  /**
116
108
  * Creates a n-triples string representation of this node
117
109
  */
118
-
119
110
  }, {
120
111
  key: "toNT",
121
112
  value: function toNT() {
122
113
  return this.toString();
123
114
  }
115
+
124
116
  /**
125
117
  * Creates a n-quads string representation of this node
126
118
  */
127
-
128
119
  }, {
129
120
  key: "toNQ",
130
121
  value: function toNQ() {
131
122
  return this.toNT();
132
123
  }
124
+
133
125
  /**
134
126
  * Creates a string representation of this node
135
127
  */
136
-
137
128
  }, {
138
129
  key: "toString",
139
130
  value: function toString() {
140
131
  throw new Error('Node.toString() is abstract - see the subclasses instead');
141
132
  }
142
133
  }]);
143
-
144
134
  return Node;
145
135
  }();
146
-
147
136
  _defineProperty(Node, "fromValue", void 0);
148
-
149
137
  _defineProperty(Node, "toJS", void 0);
150
-
151
138
  export { Node as default };
package/esm/node.js CHANGED
@@ -4,7 +4,6 @@ import { fromValue } from './collection';
4
4
  import Node from './node-internal';
5
5
  import Namespace from './namespace';
6
6
  import { isCollection, isLiteral } from './utils/terms';
7
-
8
7
  /**
9
8
  * Creates an RDF Node from a native javascript value.
10
9
  * RDF Nodes are returned unchanged, undefined returned as itself.
@@ -18,29 +17,25 @@ export default Node;
18
17
  var ns = {
19
18
  xsd: Namespace('http://www.w3.org/2001/XMLSchema#')
20
19
  };
20
+
21
21
  /**
22
22
  * Gets the javascript object equivalent to a node
23
23
  * @param term The RDF node
24
24
  */
25
-
26
25
  Node.toJS = function (term) {
27
26
  if (isCollection(term)) {
28
27
  return term.elements.map(Node.toJS); // Array node (not standard RDFJS)
29
28
  }
30
29
 
31
30
  if (!isLiteral(term)) return term;
32
-
33
31
  if (term.datatype.equals(ns.xsd('boolean'))) {
34
32
  return term.value === '1' || term.value === 'true';
35
33
  }
36
-
37
34
  if (term.datatype.equals(ns.xsd('dateTime')) || term.datatype.equals(ns.xsd('date'))) {
38
35
  return new Date(term.value);
39
36
  }
40
-
41
37
  if (term.datatype.equals(ns.xsd('integer')) || term.datatype.equals(ns.xsd('float')) || term.datatype.equals(ns.xsd('decimal'))) {
42
38
  return Number(term.value);
43
39
  }
44
-
45
40
  return term.value;
46
41
  };
package/esm/parse.js CHANGED
@@ -1,15 +1,13 @@
1
1
  import DataFactory from './factories/extended-term-factory';
2
- import jsonldParser from './jsonldparser'; // @ts-ignore is this injected?
3
-
2
+ import jsonldParser from './jsonldparser';
3
+ // @ts-ignore is this injected?
4
4
  import { Parser as N3jsParser } from 'n3'; // @@ Goal: remove this dependency
5
-
6
5
  import N3Parser from './n3parser';
7
6
  import { parseRDFaDOM } from './rdfaparser';
8
7
  import RDFParser from './rdfxmlparser';
9
8
  import sparqlUpdateParser from './patch-parser';
10
9
  import * as Util from './utils-js';
11
10
  import { TurtleContentType, N3ContentType, RDFXMLContentType, XHTMLContentType, HTMLContentType, SPARQLUpdateContentType, SPARQLUpdateSingleMatchContentType, JSONLDContentType, NQuadsContentType, NQuadsAltContentType } from './types';
12
-
13
11
  /**
14
12
  * Parse a string and put the result into the graph kb.
15
13
  * Normal method is sync.
@@ -26,7 +24,6 @@ export default function parse(str, kb, base) {
26
24
  var callback = arguments.length > 4 ? arguments[4] : undefined;
27
25
  contentType = contentType || TurtleContentType;
28
26
  contentType = contentType.split(';')[0];
29
-
30
27
  try {
31
28
  if (contentType === N3ContentType || contentType === TurtleContentType) {
32
29
  var p = N3Parser(kb, kb, base, base, null, null, '', null);
@@ -66,7 +63,6 @@ export default function parse(str, kb, base) {
66
63
  // @ts-ignore
67
64
  executeErrorCallback(e);
68
65
  }
69
-
70
66
  parse.handled = {
71
67
  'text/n3': true,
72
68
  'text/turtle': true,
@@ -79,7 +75,6 @@ export default function parse(str, kb, base) {
79
75
  'application/nquads': true,
80
76
  'application/n-quads': true
81
77
  };
82
-
83
78
  function executeCallback() {
84
79
  if (callback) {
85
80
  callback(null, kb);
@@ -87,17 +82,19 @@ export default function parse(str, kb, base) {
87
82
  return;
88
83
  }
89
84
  }
90
-
91
85
  function executeErrorCallback(e) {
92
- if ( // TODO: Always true, what is the right behavior
93
- contentType !== JSONLDContentType || // @ts-ignore always true?
94
- contentType !== NQuadsContentType || // @ts-ignore always true?
86
+ if (
87
+ // TODO: Always true, what is the right behavior
88
+ contentType !== JSONLDContentType ||
89
+ // @ts-ignore always true?
90
+ contentType !== NQuadsContentType ||
91
+ // @ts-ignore always true?
95
92
  contentType !== NQuadsAltContentType) {
96
93
  if (callback) {
97
94
  callback(e, kb);
98
95
  } else {
99
- var e2 = new Error('' + e + ' while trying to parse <' + base + '> as ' + contentType); //@ts-ignore .cause is not a default error property
100
-
96
+ var e2 = new Error('' + e + ' while trying to parse <' + base + '> as ' + contentType);
97
+ //@ts-ignore .cause is not a default error property
101
98
  e2.cause = e;
102
99
  throw e2;
103
100
  }
@@ -114,20 +111,16 @@ export default function parse(str, kb, base) {
114
111
  doc['@context']['@base'] = base
115
112
  }
116
113
  */
117
-
118
-
119
114
  function nquadCallback(err, nquads) {
120
115
  if (err) {
121
116
  callback(err, kb);
122
117
  }
123
-
124
118
  try {
125
119
  n3Parser.parse(nquads, tripleCallback);
126
120
  } catch (err) {
127
121
  callback(err, kb);
128
122
  }
129
123
  }
130
-
131
124
  function tripleCallback(err, triple) {
132
125
  if (triple) {
133
126
  kb.add(triple.subject, triple.predicate, triple.object, triple.graph);
@@ -13,98 +13,78 @@ export default function sparqlUpdateParser(str, kb, base) {
13
13
  var SQNS = Namespace('http://www.w3.org/ns/pim/patch#');
14
14
  var p = N3Parser(kb, kb, base, base, null, null, '', null);
15
15
  var clauses = {};
16
-
17
16
  var badSyntax = function badSyntax(uri, lines, str, i, why) {
18
17
  return 'Line ' + (lines + 1) + ' of <' + uri + '>: Bad syntax:\n ' + why + '\n at: "' + str.slice(i, i + 30) + '"';
19
- }; // var check = function (next, last, message) {
18
+ };
19
+
20
+ // var check = function (next, last, message) {
20
21
  // if (next < 0) {
21
22
  // throw badSyntax(p._thisDoc, p.lines, str, j, last, message)
22
23
  // }
23
24
  // return next
24
25
  // }
25
-
26
-
27
26
  i = 0;
28
27
  var query = kb.sym(base + '#query'); // Invent a URI for the query
29
-
30
28
  clauses['query'] = query; // A way of accessing it in its N3 model.
31
29
 
32
30
  while (true) {
33
31
  // console.log("A Now at i = " + i)
34
32
  j = p.skipSpace(str, i);
35
-
36
33
  if (j < 0) {
37
34
  return clauses;
38
- } // console.log("B After space at j= " + j)
39
-
40
-
35
+ }
36
+ // console.log("B After space at j= " + j)
41
37
  if (str[j] === ';') {
42
38
  i = p.skipSpace(str, j + 1);
43
-
44
39
  if (i < 0) {
45
40
  return clauses; // Allow end in a
46
41
  }
47
42
 
48
43
  j = i;
49
44
  }
50
-
51
45
  var found = false;
52
-
53
46
  for (k = 0; k < keywords.length; k++) {
54
47
  var key = keywords[k];
55
-
56
48
  if (str.slice(j, j + key.length) === key) {
57
49
  i = p.skipSpace(str, j + key.length);
58
-
59
50
  if (i < 0) {
60
51
  throw badSyntax(p._thisDoc, p.lines, str, j + key.length, 'found EOF, needed {...} after ' + key);
61
52
  }
62
-
63
53
  if ((key === 'INSERT' || key === 'DELETE') && str.slice(i, i + 4) === 'DATA') {
64
54
  // Some wanted 'DATA'. Whatever
65
55
  j = p.skipSpace(str, i + 4);
66
-
67
56
  if (j < 0) {
68
57
  throw badSyntax(p._thisDoc, p.lines, str, i + 4, 'needed {...} after INSERT DATA ' + key);
69
58
  }
70
-
71
59
  i = j;
72
60
  }
73
-
74
61
  var res2 = [];
75
62
  j = p.node(str, i, res2); // Parse all the complexity of the clause
76
63
 
77
64
  if (j < 0) {
78
65
  throw badSyntax(p._thisDoc, p.lines, str, i, 'bad syntax or EOF in {...} after ' + key);
79
66
  }
80
-
81
67
  clauses[key.toLowerCase()] = res2[0];
82
68
  kb.add(query, SQNS(key.toLowerCase()), res2[0]); // , kb.sym(base)
83
69
  // key is the keyword and res2 has the contents
84
-
85
70
  found = true;
86
71
  i = j;
87
72
  }
88
73
  }
89
-
90
74
  if (!found && str.slice(j, j + 7) === '@prefix') {
91
75
  i = p.directive(str, j);
92
-
93
76
  if (i < 0) {
94
77
  throw badSyntax(p._thisDoc, p.lines, str, i, 'bad syntax or EOF after @prefix ');
95
- } // console.log("P before dot i= " + i)
96
-
97
-
98
- i = p.checkDot(str, i); // console.log("Q after dot i= " + i)
99
-
78
+ }
79
+ // console.log("P before dot i= " + i)
80
+ i = p.checkDot(str, i);
81
+ // console.log("Q after dot i= " + i)
100
82
  found = true;
101
83
  }
102
-
103
84
  if (!found) {
104
85
  // console.log("Bad syntax " + j)
105
86
  throw badSyntax(p._thisDoc, p.lines, str, j, "Unknown syntax at start of statememt: '" + str.slice(j).slice(0, 20) + "'");
106
87
  }
107
88
  } // while
108
89
  // return clauses
109
-
110
90
  }
@@ -1,44 +1,33 @@
1
1
  import log from './log';
2
2
  export default function queryToSPARQL(query) {
3
3
  var indent = 0;
4
-
5
4
  function getSelect(query) {
6
5
  var str = addIndent() + 'SELECT ';
7
-
8
6
  for (var i = 0; i < query.vars.length; i++) {
9
7
  str += query.vars[i] + ' ';
10
8
  }
11
-
12
9
  str += '\n';
13
10
  return str;
14
11
  }
15
-
16
12
  function getPattern(pat) {
17
13
  var str = '';
18
14
  var st = pat.statements;
19
-
20
15
  for (var x in st) {
21
16
  log.debug('Found statement: ' + st);
22
17
  str += addIndent() + st[x] + '\n';
23
18
  }
24
-
25
19
  return str;
26
20
  }
27
-
28
21
  function getConstraints(pat) {
29
22
  var str = '';
30
-
31
23
  for (var v in pat.constraints) {
32
24
  var foo = pat.constraints[v];
33
25
  str += addIndent() + 'FILTER ( ' + foo.describe(v) + ' ) ' + '\n';
34
26
  }
35
-
36
27
  return str;
37
28
  }
38
-
39
29
  function getOptionals(pat) {
40
30
  var str = '';
41
-
42
31
  for (var x = 0; x < pat.optional.length; x++) {
43
32
  // alert(pat.optional.termType)
44
33
  log.debug('Found optional query');
@@ -50,10 +39,8 @@ export default function queryToSPARQL(query) {
50
39
  indent--;
51
40
  str += addIndent() + '}' + '\n';
52
41
  }
53
-
54
42
  return str;
55
43
  }
56
-
57
44
  function getWhere(pat) {
58
45
  var str = addIndent() + 'WHERE \n' + '{ \n';
59
46
  indent++;
@@ -64,20 +51,15 @@ export default function queryToSPARQL(query) {
64
51
  str += '}';
65
52
  return str;
66
53
  }
67
-
68
54
  function addIndent() {
69
55
  var str = '';
70
-
71
56
  for (var i = 0; i < indent; i++) {
72
57
  str += ' ';
73
58
  }
74
-
75
59
  return str;
76
60
  }
77
-
78
61
  function getSPARQL(query) {
79
62
  return getSelect(query) + getWhere(query.pat);
80
63
  }
81
-
82
64
  return getSPARQL(query);
83
65
  }