Skip to content

Commit fd6e7f1

Browse files
committed
BREAKING CHANGE: parse <= as log:isImpliedBy (#327)
1 parent f3898fd commit fd6e7f1

File tree

5 files changed

+139
-110
lines changed

5 files changed

+139
-110
lines changed

src/IRIs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ export default {
2626
},
2727
log: {
2828
implies: `${SWAP}log#implies`,
29+
isImpliedBy: `${SWAP}log#isImpliedBy`,
2930
},
3031
};

src/N3Lexer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export default class N3Lexer {
5353
this._endOfFile = /^(?:#[^\n\r]*)?$/;
5454
options = options || {};
5555

56+
// Whether the log:isImpliedBy predicate is supported
57+
this._isImpliedBy = options.isImpliedBy !== false;
58+
5659
this._supportsRDFStar = options.rdfStar;
5760

5861
// In line mode (N-Triples or N-Quads), only simple features may be parsed
@@ -153,8 +156,11 @@ export default class N3Lexer {
153156
else if (input.length > 1 && input[1] === '<')
154157
type = '<<', matchLength = 2;
155158
// Try to find a backwards implication arrow
156-
else if (this._n3Mode && input.length > 1 && input[1] === '=')
157-
type = 'inverse', matchLength = 2, value = '>';
159+
else if (this._n3Mode && input.length > 1 && input[1] === '=') {
160+
matchLength = 2;
161+
if (this._isImpliedBy) type = 'abbreviation', value = '<';
162+
else type = 'inverse', value = '>';
163+
}
158164
break;
159165

160166
case '>':

src/N3Parser.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ export default class N3Parser {
2929
this._supportsQuads = !(isTurtle || isTriG || isNTriples || isN3);
3030
// Support nesting of triples
3131
this._supportsRDFStar = options.rdfStar !== false;
32+
// Whether the log:isImpliedBy predicate is supported
33+
this._isImpliedBy = options.isImpliedBy !== false;
3234
// Disable relative IRIs in N-Triples or N-Quads mode
3335
if (isLineMode)
3436
this._resolveRelativeIRI = iri => { return null; };
3537
this._blankNodePrefix = typeof options.blankNodePrefix !== 'string' ? '' :
3638
options.blankNodePrefix.replace(/^(?!_:)/, '_:');
37-
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, rdfStar: this._supportsRDFStar });
39+
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, rdfStar: this._supportsRDFStar, isImpliedBy: this._isImpliedBy });
3840
// Disable explicit quantifiers by default
3941
this._explicitQuantifiers = !!options.explicitQuantifiers;
4042
}
@@ -1180,6 +1182,7 @@ function initDataFactory(parser, factory) {
11801182
'a': namedNode(namespaces.rdf.type),
11811183
'=': namedNode(namespaces.owl.sameAs),
11821184
'>': namedNode(namespaces.log.implies),
1185+
'<': namedNode(namespaces.log.isImpliedBy),
11831186
};
11841187
parser.QUANTIFIERS_GRAPH = namedNode('urn:n3:quantifiers');
11851188
}

test/N3Lexer-test.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,16 +802,30 @@ describe('Lexer', () => {
802802
it('should tokenize the left implication',
803803
shouldTokenize('<a> <= <b> ',
804804
{ type: 'IRI', value: 'a', line: 1 },
805-
{ type: 'inverse', value: '>', line: 1 },
805+
{ type: 'abbreviation', value: '<', line: 1 },
806806
{ type: 'IRI', value: 'b', line: 1 },
807807
{ type: 'eof', line: 1 }));
808808

809809
it('should tokenize a split left implication',
810810
shouldTokenize(streamOf('<a> <', '= <b> '),
811-
{ type: 'IRI', value: 'a', line: 1 },
812-
{ type: 'inverse', value: '>', line: 1 },
813-
{ type: 'IRI', value: 'b', line: 1 },
814-
{ type: 'eof', line: 1 }));
811+
{ type: 'IRI', value: 'a', line: 1 },
812+
{ type: 'abbreviation', value: '<', line: 1 },
813+
{ type: 'IRI', value: 'b', line: 1 },
814+
{ type: 'eof', line: 1 }));
815+
816+
it('should tokenize a split left implication as inverse of [=>] when isImpliedBy is disabled',
817+
shouldTokenize(new Lexer({ isImpliedBy: false }), streamOf('<a> <', '= <b> '),
818+
{ type: 'IRI', value: 'a', line: 1 },
819+
{ type: 'inverse', value: '>', line: 1 },
820+
{ type: 'IRI', value: 'b', line: 1 },
821+
{ type: 'eof', line: 1 }));
822+
823+
it('should tokenize a left implication as inverse of [=>] when isImpliedBy is disabled',
824+
shouldTokenize(new Lexer({ isImpliedBy: false }), streamOf('<a> <= <b> '),
825+
{ type: 'IRI', value: 'a', line: 1 },
826+
{ type: 'inverse', value: '>', line: 1 },
827+
{ type: 'IRI', value: 'b', line: 1 },
828+
{ type: 'eof', line: 1 }));
815829

816830
it('should tokenize paths',
817831
shouldTokenize(':joe!fam:mother!loc:office!loc:zip :joe!fam:mother^fam:mother',

0 commit comments

Comments
 (0)