n3 2.13.9 → 2.13.11
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/README.md +2 -0
- package/browser/n3.esm.min.js +2 -2
- package/browser/n3.min.js +2 -2
- package/lib/N3DataFactory.js +2 -2
- package/lib/N3Store.js +9 -4
- package/package.json +1 -1
- package/src/N3DataFactory.js +2 -2
- package/src/N3Store.js +9 -5
package/lib/N3DataFactory.js
CHANGED
|
@@ -137,10 +137,10 @@ class Literal extends Term {
|
|
|
137
137
|
|
|
138
138
|
// ### The direction of this literal
|
|
139
139
|
get direction() {
|
|
140
|
-
// Find the last double dash after the closing quote (e.g., '"abc"@en-us--ltr')
|
|
140
|
+
// Find the last double dash after the closing quote and language tag (e.g., '"abc"@en-us--ltr')
|
|
141
141
|
const id = this.id;
|
|
142
142
|
const endPos = id.lastIndexOf('"');
|
|
143
|
-
const dirPos = id.lastIndexOf('--');
|
|
143
|
+
const dirPos = id[endPos + 1] === '@' ? id.lastIndexOf('--') : -1;
|
|
144
144
|
return dirPos > endPos && dirPos + 2 < id.length ? id.substr(dirPos + 2).toLowerCase() : '';
|
|
145
145
|
}
|
|
146
146
|
|
package/lib/N3Store.js
CHANGED
|
@@ -37,8 +37,11 @@ function hasInIndex(index0, key0, key1, key2) {
|
|
|
37
37
|
// that starts with such a marker (as relative IRIs can) is wrapped in < and >.
|
|
38
38
|
const markedIRI = /^[?_"[.<]/;
|
|
39
39
|
function entityKey(term) {
|
|
40
|
-
// Strings are term ids, which only need wrapping when they are IRIs starting with <
|
|
41
|
-
if (typeof term === 'string')
|
|
40
|
+
// Strings are term ids, which only need wrapping when they are IRIs starting with < or .
|
|
41
|
+
if (typeof term === 'string') {
|
|
42
|
+
const first = term.charCodeAt(0);
|
|
43
|
+
return first !== 0x3C && first !== 0x2E || term === '<>' ? term : `<${term}>`;
|
|
44
|
+
}
|
|
42
45
|
// IDs of IRIs usually start with a lowercase scheme letter, which never marks a term type
|
|
43
46
|
const id = (0, _N3DataFactory.termToId)(term);
|
|
44
47
|
if (id.charCodeAt(0) >= 0x61 || !term) return id;
|
|
@@ -97,10 +100,12 @@ class N3EntityIndex {
|
|
|
97
100
|
|
|
98
101
|
// Returns the numeric id of a term given as a string id
|
|
99
102
|
_stringToNumericId(term) {
|
|
100
|
-
// The string is the key unless it is an IRI starting with
|
|
103
|
+
// The string is the key unless it is an IRI starting with < (which starts the keys of
|
|
104
|
+
// wrapped IRIs) or . (which starts the keys of quoted triples). Read the first character
|
|
101
105
|
// from the stored key after a match, which is cheaper than from a concatenated string.
|
|
102
106
|
const id = this._ids[term];
|
|
103
|
-
|
|
107
|
+
const first = id ? this._entities[id].charCodeAt(0) : term.charCodeAt(0);
|
|
108
|
+
if (first !== 0x3C && first !== 0x2E) return id;
|
|
104
109
|
return term === '<>' ? id : this._ids[`<${term}>`];
|
|
105
110
|
}
|
|
106
111
|
_termToNewNumericId(term) {
|
package/package.json
CHANGED
package/src/N3DataFactory.js
CHANGED
|
@@ -125,10 +125,10 @@ export class Literal extends Term {
|
|
|
125
125
|
|
|
126
126
|
// ### The direction of this literal
|
|
127
127
|
get direction() {
|
|
128
|
-
// Find the last double dash after the closing quote (e.g., '"abc"@en-us--ltr')
|
|
128
|
+
// Find the last double dash after the closing quote and language tag (e.g., '"abc"@en-us--ltr')
|
|
129
129
|
const id = this.id;
|
|
130
130
|
const endPos = id.lastIndexOf('"');
|
|
131
|
-
const dirPos = id.lastIndexOf('--');
|
|
131
|
+
const dirPos = id[endPos + 1] === '@' ? id.lastIndexOf('--') : -1;
|
|
132
132
|
return dirPos > endPos && dirPos + 2 < id.length ? id.substr(dirPos + 2).toLowerCase() : '';
|
|
133
133
|
}
|
|
134
134
|
|
package/src/N3Store.js
CHANGED
|
@@ -28,9 +28,11 @@ function hasInIndex(index0, key0, key1, key2) {
|
|
|
28
28
|
// that starts with such a marker (as relative IRIs can) is wrapped in < and >.
|
|
29
29
|
const markedIRI = /^[?_"[.<]/;
|
|
30
30
|
function entityKey(term) {
|
|
31
|
-
// Strings are term ids, which only need wrapping when they are IRIs starting with <
|
|
32
|
-
if (typeof term === 'string')
|
|
33
|
-
|
|
31
|
+
// Strings are term ids, which only need wrapping when they are IRIs starting with < or .
|
|
32
|
+
if (typeof term === 'string') {
|
|
33
|
+
const first = term.charCodeAt(0);
|
|
34
|
+
return first !== 0x3C && first !== 0x2E || term === '<>' ? term : `<${term}>`;
|
|
35
|
+
}
|
|
34
36
|
// IDs of IRIs usually start with a lowercase scheme letter, which never marks a term type
|
|
35
37
|
const id = termToId(term);
|
|
36
38
|
if (id.charCodeAt(0) >= 0x61 || !term)
|
|
@@ -102,10 +104,12 @@ export class N3EntityIndex {
|
|
|
102
104
|
|
|
103
105
|
// Returns the numeric id of a term given as a string id
|
|
104
106
|
_stringToNumericId(term) {
|
|
105
|
-
// The string is the key unless it is an IRI starting with
|
|
107
|
+
// The string is the key unless it is an IRI starting with < (which starts the keys of
|
|
108
|
+
// wrapped IRIs) or . (which starts the keys of quoted triples). Read the first character
|
|
106
109
|
// from the stored key after a match, which is cheaper than from a concatenated string.
|
|
107
110
|
const id = this._ids[term];
|
|
108
|
-
|
|
111
|
+
const first = id ? this._entities[id].charCodeAt(0) : term.charCodeAt(0);
|
|
112
|
+
if (first !== 0x3C && first !== 0x2E)
|
|
109
113
|
return id;
|
|
110
114
|
return term === '<>' ? id : this._ids[`<${term}>`];
|
|
111
115
|
}
|