Skip to content

Commit

Permalink
Add optional direction for literals
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Nov 10, 2023
1 parent 634bf42 commit e5fe4c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/SparqlJsonParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export class SparqlJsonParser {
break;
case 'literal':
if (rawValue['xml:lang']) {
value = this.dataFactory.literal(rawValue.value, rawValue['xml:lang']);
const language = rawValue['xml:lang'];
const direction = rawValue['its:dir'];
value = this.dataFactory.literal(rawValue.value, { language, direction });

Check failure on line 115 in lib/SparqlJsonParser.ts

View workflow job for this annotation

GitHub Actions / lint

Argument of type '{ language: any; direction: any; }' is not assignable to parameter of type 'string | NamedNode<string>'.

Check failure on line 115 in lib/SparqlJsonParser.ts

View workflow job for this annotation

GitHub Actions / webpack

Argument of type '{ language: any; direction: any; }' is not assignable to parameter of type 'string | NamedNode<string>'.

Check failure on line 115 in lib/SparqlJsonParser.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 14.x)

Argument of type '{ language: any; direction: any; }' is not assignable to parameter of type 'string | NamedNode<string>'.

Check failure on line 115 in lib/SparqlJsonParser.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 16.x)

Argument of type '{ language: any; direction: any; }' is not assignable to parameter of type 'string | NamedNode<string>'.

Check failure on line 115 in lib/SparqlJsonParser.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18.x)

Argument of type '{ language: any; direction: any; }' is not assignable to parameter of type 'string | NamedNode<string>'.
} else if (rawValue.datatype) {
value = this.dataFactory.literal(rawValue.value, this.dataFactory.namedNode(rawValue.datatype));
} else {
Expand Down
6 changes: 6 additions & 0 deletions test/SparqlJsonParser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ describe('SparqlJsonParser', () => {
})).toEqual({ '?book': DF.literal('abc', 'en-us') });
});

it('should convert bindings with languaged literals with direction', () => {
return expect(parser.parseJsonBindings({
book: { 'type': 'literal', 'value': 'abc', 'xml:lang': 'en-us', 'its:dir': 'ltr' },
})).toEqual({ '?book': DF.literal('abc', { language: 'en-us', direction: 'ltr' }) });
});

it('should convert bindings with datatyped literals', () => {
return expect(parser.parseJsonBindings({
book: { type: 'literal', value: 'abc', datatype: 'http://ex' },
Expand Down

0 comments on commit e5fe4c9

Please sign in to comment.