Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: parse <= as log:isImpliedBy #327

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/IRIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export default {
},
log: {
implies: `${SWAP}log#implies`,
isImpliedBy: `${SWAP}log#isImpliedBy`,
},
};
11 changes: 9 additions & 2 deletions src/N3Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export default class N3Lexer {
this._endOfFile = /^(?:#[^\n\r]*)?$/;
options = options || {};

// Whether the log:isImpliedBy predicate is supported
this._isImpliedBy = options.isImpliedBy !== false;

// In line mode (N-Triples or N-Quads), only simple features may be parsed
if (this._lineMode = !!options.lineMode) {
this._n3Mode = false;
Expand Down Expand Up @@ -151,8 +154,12 @@ export default class N3Lexer {
else if (input.length > 1 && input[1] === '<')
type = '<<', matchLength = 2;
// Try to find a backwards implication arrow
else if (this._n3Mode && input.length > 1 && input[1] === '=')
type = 'inverse', matchLength = 2, value = '>';
else if (this._n3Mode && input.length > 1 && input[1] === '=') {
if (this._isImpliedBy)
type = 'abbreviation', matchLength = 2, value = '<';
else
type = 'inverse', matchLength = 2, value = '>';
}
break;

case '>':
Expand Down
3 changes: 2 additions & 1 deletion src/N3Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class N3Parser {
this._resolveRelativeIRI = iri => { return null; };
this._blankNodePrefix = typeof options.blankNodePrefix !== 'string' ? '' :
options.blankNodePrefix.replace(/^(?!_:)/, '_:');
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3 });
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, isImpliedBy: options.isImpliedBy });
// Disable explicit quantifiers by default
this._explicitQuantifiers = !!options.explicitQuantifiers;
}
Expand Down Expand Up @@ -1054,6 +1054,7 @@ function initDataFactory(parser, factory) {
'a': namedNode(namespaces.rdf.type),
'=': namedNode(namespaces.owl.sameAs),
'>': namedNode(namespaces.log.implies),
'<': namedNode(namespaces.log.isImpliedBy),
};
parser.QUANTIFIERS_GRAPH = namedNode('urn:n3:quantifiers');
}
Expand Down
16 changes: 15 additions & 1 deletion test/N3Lexer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,26 @@ describe('Lexer', () => {
it('should tokenize the left implication',
shouldTokenize('<a> <= <b> ',
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'inverse', value: '>', line: 1 },
{ type: 'abbreviation', value: '<', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'eof', line: 1 }));

it('should tokenize a split left implication',
shouldTokenize(streamOf('<a> <', '= <b> '),
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'abbreviation', value: '<', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'eof', line: 1 }));

it('should tokenize a split left implication as inverse of [=>] when isImpliedBy is disabled',
shouldTokenize(new Lexer({ isImpliedBy: false }), streamOf('<a> <', '= <b> '),
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'inverse', value: '>', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'eof', line: 1 }));

it('should tokenize a left implication as inverse of [=>] when isImpliedBy is disabled',
shouldTokenize(new Lexer({ isImpliedBy: false }), streamOf('<a> <= <b> '),
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'inverse', value: '>', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
Expand Down
Loading