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

Hashtag (#) from @base prefix is lost during parsing? #15

Closed
Lenostatos opened this issue May 29, 2024 · 3 comments
Closed

Hashtag (#) from @base prefix is lost during parsing? #15

Lenostatos opened this issue May 29, 2024 · 3 comments

Comments

@Lenostatos
Copy link

Hello,

when I execute the example code from the README with the following turtle data, the resulting quads are not what I am expecting.

import ParserN3 from '@rdfjs/parser-n3'
import { Readable } from 'readable-stream'

const parserN3 = new ParserN3()

const input = Readable.from(`
@base <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <../../1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <> .
@prefix owl: <../../2002/07/owl#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .

<>
    dc:title "The RDF Schema vocabulary (RDFS)" ;
    a owl:Ontology ;
    rdfs:seeAlso <rdf-schema-more> .

rdfs:Class
    a rdfs:Class ;
    rdfs:comment "The class of classes." ;
    rdfs:isDefinedBy <> ;
    rdfs:label "Class" ;
    rdfs:subClassOf rdfs:Resource .
`)

const output = parserN3.import(input)

output.on('data', quad => {
  console.log(`quad: ${quad.subject.value} - ${quad.predicate.value} - ${quad.object.value}`)
})

output.on('prefix', (prefix, ns) => {
  console.log(`prefix: ${prefix} ${ns.value}`)
})

Please note the missing hash symbol (#) at the end of the rdfs prefix in line 2, which is propagated to every place where the prefix was used in the turtle data:
image

I hope this is not just me being stupid, but at least on this website, the turtle is parsed as expected.

Thank you for your time!

@bergos
Copy link
Contributor

bergos commented Jun 2, 2024

According to the Turtle specification, the base IRI should be resolved as described in RFC 3986, which says:

If the base URI is obtained from a URI reference, then that reference must be converted to absolute form and stripped of any fragment component prior to its use as a base URI.

To my understanding, the behavior is correct, and the parsed output of the mentioned web page is wrong.

This library is just a wrapper for N3.js, where the parsing of the base and prefixes happens. Let's forward the question:

@RubenVerborgh can you confirm my assumption?

@RubenVerborgh
Copy link
Contributor

Correct indeed; we have a whole bunch of tests for IRI resolution cases (https://github.com/rdfjs/N3.js/blob/v1.17.3/test/N3Parser-test.js#L2591), because we discovered back in the day that many parsers had different interpretations (https://lists.w3.org/Archives/Public/public-rdf-comments/2015Aug/0000.html).

@Lenostatos
Copy link
Author

I see, thank you very much @bergos and @RubenVerborgh for your time! Then I will forward this to my turtle source 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants