Skip to content

Commit

Permalink
BREAKING CHANGE: parse <= as log:isImpliedBy (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Mar 27, 2023
1 parent f3898fd commit fd6e7f1
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 110 deletions.
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`,
},
};
10 changes: 8 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;

this._supportsRDFStar = options.rdfStar;

// In line mode (N-Triples or N-Quads), only simple features may be parsed
Expand Down Expand Up @@ -153,8 +156,11 @@ 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] === '=') {
matchLength = 2;
if (this._isImpliedBy) type = 'abbreviation', value = '<';
else type = 'inverse', value = '>';
}
break;

case '>':
Expand Down
5 changes: 4 additions & 1 deletion src/N3Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ export default class N3Parser {
this._supportsQuads = !(isTurtle || isTriG || isNTriples || isN3);
// Support nesting of triples
this._supportsRDFStar = options.rdfStar !== false;
// Whether the log:isImpliedBy predicate is supported
this._isImpliedBy = options.isImpliedBy !== false;
// Disable relative IRIs in N-Triples or N-Quads mode
if (isLineMode)
this._resolveRelativeIRI = iri => { return null; };
this._blankNodePrefix = typeof options.blankNodePrefix !== 'string' ? '' :
options.blankNodePrefix.replace(/^(?!_:)/, '_:');
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, rdfStar: this._supportsRDFStar });
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, rdfStar: this._supportsRDFStar, isImpliedBy: this._isImpliedBy });
// Disable explicit quantifiers by default
this._explicitQuantifiers = !!options.explicitQuantifiers;
}
Expand Down Expand Up @@ -1180,6 +1182,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
24 changes: 19 additions & 5 deletions test/N3Lexer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,16 +802,30 @@ 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: 'inverse', value: '>', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'eof', line: 1 }));
{ 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 },
{ type: 'eof', line: 1 }));

it('should tokenize paths',
shouldTokenize(':joe!fam:mother!loc:office!loc:zip :joe!fam:mother^fam:mother',
Expand Down
Loading

0 comments on commit fd6e7f1

Please sign in to comment.