diff --git a/lib/Util.ts b/lib/Util.ts index 7aa160f..fb78b4b 100644 --- a/lib/Util.ts +++ b/lib/Util.ts @@ -98,6 +98,9 @@ export class Util { if (baseIRI.endsWith('.ttl')) { return data.pipe(new GeneralizedN3StreamParser({ baseIRI, format: 'text/turtle', })); } + if (baseIRI.endsWith('.trig')) { + return data.pipe(new GeneralizedN3StreamParser({ baseIRI, format: 'application/trig', })); + } throw new Error(`Could not parse the RDF serialization ${contentType} on ${baseIRI}`); } diff --git a/test/Util-test.ts b/test/Util-test.ts index e3f6951..dba2d3b 100644 --- a/test/Util-test.ts +++ b/test/Util-test.ts @@ -183,6 +183,15 @@ describe('Util', () => { ]); }); + it('should workaround an unknown content type with explicit url extension for trig', async () => { + expect(await arrayifyStream(Util.parseRdfRaw('unknown', 'http://example.org/apples.trig', + streamifyString(' .')))) + .toEqualRdfQuadArray([ + DF.quad(DF.namedNode('http://example.org/a'), DF.namedNode('http://example.org/b'), + DF.namedNode('http://example.org/c')), + ]); + }); + it('should parse application/x-turtle streams', async () => { expect(await arrayifyStream(Util.parseRdfRaw('application/x-turtle', 'http://example.org/', streamifyString(' .'))))