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

Prefixes are not preserved when parsing and then serializing Turtle #4929

Open
reckart opened this issue Mar 6, 2024 · 0 comments
Open

Prefixes are not preserved when parsing and then serializing Turtle #4929

reckart opened this issue Mar 6, 2024 · 0 comments
Labels
🐞 bug issue is a bug

Comments

@reckart
Copy link
Contributor

reckart commented Mar 6, 2024

Current Behavior

For certain types of IRIs / prefix declarations, the declarations are not preserved during a round trip.

When I parse this

prefix server-news: <news:comp.infosystems.www.servers.> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
server-news:unix rdfs:label "News on Unix" .
server-news:windows rdfs:label "News on Windows" .

and serialize it out again, it comes out as this

@prefix server-news: <news:comp.infosystems.www.servers.> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<news:comp.infosystems.www.servers.unix> rdfs:label "News on Unix" .
<news:comp.infosystems.www.servers.windows> rdfs:label "News on Windows" .

That seems to be because the AbstractRDFParser fails to consider the namespace declarations from the Turtle when generating the IRI instances.

Expected Behavior

The parse should consider the prefix declarations when parsing and create the namespaces and IRIs accordingly in the model. When serializing, these declarations should be respected (cf. #4921).

Steps To Reproduce

	@Test
	public void testUnusualIrisAndPrefixesParseWriteCompare() throws Exception {
		String data = "@prefix server-news: <news:comp.infosystems.www.servers.> .\n" +
				"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" +
				"server-news:unix rdfs:label \"News on Unix\" .\n" +
				"server-news:windows rdfs:label \"News on Windows\" .\n";

		var expected = Rio.parse(new StringReader(data), "", RDFFormat.TURTLE);

		var stringWriter = new StringWriter();
		var config = new WriterConfig();
		config.set(BasicWriterSettings.INLINE_BLANK_NODES, false);
		config.set(BasicWriterSettings.PRETTY_PRINT, false);
		Rio.write(expected, stringWriter, RDFFormat.TURTLE, config);

		var actual = Rio.parse(new StringReader(stringWriter.toString()), "", RDFFormat.TURTLE);
		assertThat(Models.isomorphic(expected, actual)).as("isomorphic").isTrue();

		assertThat(stringWriter.toString()).isEqualTo(data);
	}

Version

4.3.10

Are you interested in contributing a solution yourself?

No

Anything else?

No response

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

No branches or pull requests

1 participant