n3 2.10.2 → 2.10.3
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.
- package/browser/n3.esm.min.js +2 -2
- package/browser/n3.min.js +2 -2
- package/lib/N3Writer.js +19 -3
- package/package.json +1 -1
- package/src/N3Writer.js +20 -4
package/browser/n3.esm.min.js
CHANGED
|
@@ -7,9 +7,9 @@ var Ol=Object.create;var rr=Object.defineProperty,Dl=Object.defineProperties,Ml=
|
|
|
7
7
|
`)+(Dt.equals(n)?"":`${this._encodeIriOrBlank(n)} {
|
|
8
8
|
`)),this._graph=n,this._subject=null),e===this._subject||e.equals(this._subject)?r===this._predicate||r.equals(this._predicate)?this._write(`, ${this._encodeObject(i)}`,s):this._write(`;
|
|
9
9
|
${this._encodePredicate(this._predicate=r)} ${this._encodeObject(i)}`,s):this._write(`${(this._subject===null?"":`.
|
|
10
|
-
`)+this._encodeSubject(this._subject=e)} ${this._encodePredicate(this._predicate=r)} ${this._encodeObject(i)}`,s)}catch(o){s&&s(o)}}_writeQuadLine(e,r,i,n,s){delete this._prefixMatch,this._write(this.quadToString(e,r,i,n),s)}quadToString(e,r,i,n){return`${this._encodeSubject(e)} ${this._encodeIriOrBlank(r)} ${this._encodeObject(i)}${n&&!ae(n)?` ${this._encodeIriOrBlank(n)} .
|
|
10
|
+
`)+this._encodeSubject(this._subject=e)} ${this._encodePredicate(this._predicate=r)} ${this._encodeObject(i)}`,s)}catch(o){s&&s(o)}}_writeQuadLine(e,r,i,n,s){delete this._prefixMatch,this._write(this.quadToString(e,r,i,n),s)}quadToString(e,r,i,n){return`${this._encodeSubject(e)} ${r.termType==="Literal"?this._encodeLiteral(r):this._encodeIriOrBlank(r)} ${this._encodeObject(i)}${n&&!ae(n)?` ${this._encodeIriOrBlank(n)} .
|
|
11
11
|
`:` .
|
|
12
|
-
`}`}quadsToString(e){let r="";for(let i of e)r+=this.quadToString(i.subject,i.predicate,i.object,i.graph);return r}_encodeSubject(e){
|
|
12
|
+
`}`}quadsToString(e){let r="";for(let i of e)r+=this.quadToString(i.subject,i.predicate,i.object,i.graph);return r}_encodeSubject(e){switch(e.termType){case"Quad":return this._encodeQuad(e);case"Literal":return this._encodeLiteral(e);default:return this._encodeIriOrBlank(e)}}_encodeIriOrBlank(e){if(e.termType!=="NamedNode")return this._lists&&e.value in this._lists&&(e=this.list(this._lists[e.value])),e.termType==="Variable"?`?${e.value}`:"id"in e?e.id:`_:${e.value}`;let r=e.value;this._baseIri&&(r=this._baseIri.toRelative(r)),_s.test(r)&&(r=r.replace(ps,bs));let i=this._hasPrefixes?this._prefixRegex.exec(r):null;return i?i[1]?this._prefixIRIs[i[1]]+i[2]:r:`<${r}>`}_encodeLiteral(e){let r=e.value;_s.test(r)&&(r=r.replace(ps,bs));let i=e.language;if(i){let n=e.direction,s=n?`--${n}`:"";return`"${r}"@${i}${s}`}if(this._lineMode){if(e.datatype.value===_t.string)return`"${r}"`}else switch(e.datatype.value){case _t.string:return`"${r}"`;case _t.boolean:if(r==="true"||r==="false")return r;break;case _t.integer:if(/^[+-]?\d+$/.test(r))return r;break;case _t.decimal:if(/^[+-]?\d*\.\d+$/.test(r))return r;break;case _t.double:if(/^[+-]?(?:\d+\.\d*|\.?\d+)[eE][+-]?\d+$/.test(r))return r;break}return`"${r}"^^${this._encodeIriOrBlank(e.datatype)}`}_encodePredicate(e){switch(e.termType){case"NamedNode":return e.value===qu.type?"a":this._encodeIriOrBlank(e);case"Literal":return this._encodeLiteral(e);default:return this._encodeIriOrBlank(e)}}_encodeObject(e){switch(e.termType){case"Quad":return this._encodeQuad(e);case"Literal":return this._encodeLiteral(e);default:return this._encodeIriOrBlank(e)}}_encodeQuad({subject:e,predicate:r,object:i,graph:n}){return`<<(${this._encodeSubject(e)} ${this._encodePredicate(r)} ${this._encodeObject(i)}${ae(n)?"":` ${this._encodeIriOrBlank(n)}`})>>`}_blockedWrite(){throw new Error("Cannot write because the writer has been closed.")}addQuad(e,r,i,n,s){i===void 0?this._writeQuad(e.subject,e.predicate,e.object,e.graph,r):typeof n=="function"?this._writeQuad(e,r,i,Dt,n):this._writeQuad(e,r,i,n||Dt,s)}addQuads(e){for(let r=0;r<e.length;r++)this.addQuad(e[r])}addPrefix(e,r,i){let n={};n[e]=r,this.addPrefixes(n,i)}addPrefixes(e,r){if(!this._prefixIRIs)return r&&r();let i=!1;for(let n in e){let s=e[n];typeof s!="string"&&(s=s.value),i=!0,this._subject!==null&&(this._write(this._inDefaultGraph?`.
|
|
13
13
|
`:`
|
|
14
14
|
}
|
|
15
15
|
`),this._subject=null,this._graph=""),this._prefixIRIs[s]=n+=":",this._write(`@prefix ${n} <${s}>.
|
package/browser/n3.min.js
CHANGED
|
@@ -7,9 +7,9 @@ var N3=(()=>{var Ml=Object.create;var kt=Object.defineProperty,$l=Object.defineP
|
|
|
7
7
|
`)+(Wt.equals(n)?"":`${this._encodeIriOrBlank(n)} {
|
|
8
8
|
`)),this._graph=n,this._subject=null),e===this._subject||e.equals(this._subject)?r===this._predicate||r.equals(this._predicate)?this._write(`, ${this._encodeObject(i)}`,s):this._write(`;
|
|
9
9
|
${this._encodePredicate(this._predicate=r)} ${this._encodeObject(i)}`,s):this._write(`${(this._subject===null?"":`.
|
|
10
|
-
`)+this._encodeSubject(this._subject=e)} ${this._encodePredicate(this._predicate=r)} ${this._encodeObject(i)}`,s)}catch(o){s&&s(o)}}_writeQuadLine(e,r,i,n,s){delete this._prefixMatch,this._write(this.quadToString(e,r,i,n),s)}quadToString(e,r,i,n){return`${this._encodeSubject(e)} ${this._encodeIriOrBlank(r)} ${this._encodeObject(i)}${n&&!fe(n)?` ${this._encodeIriOrBlank(n)} .
|
|
10
|
+
`)+this._encodeSubject(this._subject=e)} ${this._encodePredicate(this._predicate=r)} ${this._encodeObject(i)}`,s)}catch(o){s&&s(o)}}_writeQuadLine(e,r,i,n,s){delete this._prefixMatch,this._write(this.quadToString(e,r,i,n),s)}quadToString(e,r,i,n){return`${this._encodeSubject(e)} ${r.termType==="Literal"?this._encodeLiteral(r):this._encodeIriOrBlank(r)} ${this._encodeObject(i)}${n&&!fe(n)?` ${this._encodeIriOrBlank(n)} .
|
|
11
11
|
`:` .
|
|
12
|
-
`}`}quadsToString(e){let r="";for(let i of e)r+=this.quadToString(i.subject,i.predicate,i.object,i.graph);return r}_encodeSubject(e){
|
|
12
|
+
`}`}quadsToString(e){let r="";for(let i of e)r+=this.quadToString(i.subject,i.predicate,i.object,i.graph);return r}_encodeSubject(e){switch(e.termType){case"Quad":return this._encodeQuad(e);case"Literal":return this._encodeLiteral(e);default:return this._encodeIriOrBlank(e)}}_encodeIriOrBlank(e){if(e.termType!=="NamedNode")return this._lists&&e.value in this._lists&&(e=this.list(this._lists[e.value])),e.termType==="Variable"?`?${e.value}`:"id"in e?e.id:`_:${e.value}`;let r=e.value;this._baseIri&&(r=this._baseIri.toRelative(r)),ys.test(r)&&(r=r.replace(gs,ms));let i=this._hasPrefixes?this._prefixRegex.exec(r):null;return i?i[1]?this._prefixIRIs[i[1]]+i[2]:r:`<${r}>`}_encodeLiteral(e){let r=e.value;ys.test(r)&&(r=r.replace(gs,ms));let i=e.language;if(i){let n=e.direction,s=n?`--${n}`:"";return`"${r}"@${i}${s}`}if(this._lineMode){if(e.datatype.value===yt.string)return`"${r}"`}else switch(e.datatype.value){case yt.string:return`"${r}"`;case yt.boolean:if(r==="true"||r==="false")return r;break;case yt.integer:if(/^[+-]?\d+$/.test(r))return r;break;case yt.decimal:if(/^[+-]?\d*\.\d+$/.test(r))return r;break;case yt.double:if(/^[+-]?(?:\d+\.\d*|\.?\d+)[eE][+-]?\d+$/.test(r))return r;break}return`"${r}"^^${this._encodeIriOrBlank(e.datatype)}`}_encodePredicate(e){switch(e.termType){case"NamedNode":return e.value===Wu.type?"a":this._encodeIriOrBlank(e);case"Literal":return this._encodeLiteral(e);default:return this._encodeIriOrBlank(e)}}_encodeObject(e){switch(e.termType){case"Quad":return this._encodeQuad(e);case"Literal":return this._encodeLiteral(e);default:return this._encodeIriOrBlank(e)}}_encodeQuad({subject:e,predicate:r,object:i,graph:n}){return`<<(${this._encodeSubject(e)} ${this._encodePredicate(r)} ${this._encodeObject(i)}${fe(n)?"":` ${this._encodeIriOrBlank(n)}`})>>`}_blockedWrite(){throw new Error("Cannot write because the writer has been closed.")}addQuad(e,r,i,n,s){i===void 0?this._writeQuad(e.subject,e.predicate,e.object,e.graph,r):typeof n=="function"?this._writeQuad(e,r,i,Wt,n):this._writeQuad(e,r,i,n||Wt,s)}addQuads(e){for(let r=0;r<e.length;r++)this.addQuad(e[r])}addPrefix(e,r,i){let n={};n[e]=r,this.addPrefixes(n,i)}addPrefixes(e,r){if(!this._prefixIRIs)return r&&r();let i=!1;for(let n in e){let s=e[n];typeof s!="string"&&(s=s.value),i=!0,this._subject!==null&&(this._write(this._inDefaultGraph?`.
|
|
13
13
|
`:`
|
|
14
14
|
}
|
|
15
15
|
`),this._subject=null,this._graph=""),this._prefixIRIs[s]=n+=":",this._write(`@prefix ${n} <${s}>.
|
package/lib/N3Writer.js
CHANGED
|
@@ -135,7 +135,7 @@ class N3Writer {
|
|
|
135
135
|
|
|
136
136
|
// ### `quadToString` serializes a quad as a string
|
|
137
137
|
quadToString(subject, predicate, object, graph) {
|
|
138
|
-
return `${this._encodeSubject(subject)} ${this._encodeIriOrBlank(predicate)} ${this._encodeObject(object)}${graph && !(0, _N3Util.isDefaultGraph)(graph) ? ` ${this._encodeIriOrBlank(graph)} .\n` : ' .\n'}`;
|
|
138
|
+
return `${this._encodeSubject(subject)} ${predicate.termType === 'Literal' ? this._encodeLiteral(predicate) : this._encodeIriOrBlank(predicate)} ${this._encodeObject(object)}${graph && !(0, _N3Util.isDefaultGraph)(graph) ? ` ${this._encodeIriOrBlank(graph)} .\n` : ' .\n'}`;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// ### `quadsToString` serializes an array of quads as a string
|
|
@@ -147,7 +147,15 @@ class N3Writer {
|
|
|
147
147
|
|
|
148
148
|
// ### `_encodeSubject` represents a subject
|
|
149
149
|
_encodeSubject(entity) {
|
|
150
|
-
|
|
150
|
+
switch (entity.termType) {
|
|
151
|
+
case 'Quad':
|
|
152
|
+
return this._encodeQuad(entity);
|
|
153
|
+
// Literal subjects are only valid in N3
|
|
154
|
+
case 'Literal':
|
|
155
|
+
return this._encodeLiteral(entity);
|
|
156
|
+
default:
|
|
157
|
+
return this._encodeIriOrBlank(entity);
|
|
158
|
+
}
|
|
151
159
|
}
|
|
152
160
|
|
|
153
161
|
// ### `_encodeIriOrBlank` represents an IRI or blank node
|
|
@@ -214,7 +222,15 @@ class N3Writer {
|
|
|
214
222
|
|
|
215
223
|
// ### `_encodePredicate` represents a predicate
|
|
216
224
|
_encodePredicate(predicate) {
|
|
217
|
-
|
|
225
|
+
switch (predicate.termType) {
|
|
226
|
+
case 'NamedNode':
|
|
227
|
+
return predicate.value === rdf.type ? 'a' : this._encodeIriOrBlank(predicate);
|
|
228
|
+
// Literal predicates are only valid in N3
|
|
229
|
+
case 'Literal':
|
|
230
|
+
return this._encodeLiteral(predicate);
|
|
231
|
+
default:
|
|
232
|
+
return this._encodeIriOrBlank(predicate);
|
|
233
|
+
}
|
|
218
234
|
}
|
|
219
235
|
|
|
220
236
|
// ### `_encodeObject` represents an object
|
package/package.json
CHANGED
package/src/N3Writer.js
CHANGED
|
@@ -129,7 +129,8 @@ export default class N3Writer {
|
|
|
129
129
|
// ### `quadToString` serializes a quad as a string
|
|
130
130
|
quadToString(subject, predicate, object, graph) {
|
|
131
131
|
return `${this._encodeSubject(subject)} ${
|
|
132
|
-
|
|
132
|
+
predicate.termType === 'Literal' ?
|
|
133
|
+
this._encodeLiteral(predicate) : this._encodeIriOrBlank(predicate)} ${
|
|
133
134
|
this._encodeObject(object)
|
|
134
135
|
}${graph && !isDefaultGraph(graph) ? ` ${this._encodeIriOrBlank(graph)} .\n` : ' .\n'}`;
|
|
135
136
|
}
|
|
@@ -144,8 +145,15 @@ export default class N3Writer {
|
|
|
144
145
|
|
|
145
146
|
// ### `_encodeSubject` represents a subject
|
|
146
147
|
_encodeSubject(entity) {
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
switch (entity.termType) {
|
|
149
|
+
case 'Quad':
|
|
150
|
+
return this._encodeQuad(entity);
|
|
151
|
+
// Literal subjects are only valid in N3
|
|
152
|
+
case 'Literal':
|
|
153
|
+
return this._encodeLiteral(entity);
|
|
154
|
+
default:
|
|
155
|
+
return this._encodeIriOrBlank(entity);
|
|
156
|
+
}
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
// ### `_encodeIriOrBlank` represents an IRI or blank node
|
|
@@ -223,7 +231,15 @@ export default class N3Writer {
|
|
|
223
231
|
|
|
224
232
|
// ### `_encodePredicate` represents a predicate
|
|
225
233
|
_encodePredicate(predicate) {
|
|
226
|
-
|
|
234
|
+
switch (predicate.termType) {
|
|
235
|
+
case 'NamedNode':
|
|
236
|
+
return predicate.value === rdf.type ? 'a' : this._encodeIriOrBlank(predicate);
|
|
237
|
+
// Literal predicates are only valid in N3
|
|
238
|
+
case 'Literal':
|
|
239
|
+
return this._encodeLiteral(predicate);
|
|
240
|
+
default:
|
|
241
|
+
return this._encodeIriOrBlank(predicate);
|
|
242
|
+
}
|
|
227
243
|
}
|
|
228
244
|
|
|
229
245
|
// ### `_encodeObject` represents an object
|