diff --git a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala index 65f65ac..7fcde62 100644 --- a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala +++ b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala @@ -10,6 +10,7 @@ import eu.neverblink.jelly.convert.jena.JenaConverterFactory import eu.neverblink.jelly.convert.jena.riot.{JellyFormatVariant, JellyLanguage, JellyStreamWriter} import eu.neverblink.jelly.core.proto.google.v1 as google import eu.neverblink.jelly.core.proto.v1.{LogicalStreamType, PhysicalStreamType, RdfStreamOptions} +import org.apache.jena.riot.lang.LabelToNode import org.apache.jena.riot.system.StreamRDFWriter import org.apache.jena.riot.{Lang, RDFParser, RIOT} @@ -159,7 +160,10 @@ object RdfToJelly extends RdfSerDesCommand[RdfToJellyOptions, RdfFormat.Readable .build() JellyStreamWriter(JenaConverterFactory.getInstance(), variant, outputStream) - RDFParser.source(inputStream).lang(jenaLang).parse(jellyWriter) + RDFParser.source(inputStream) + .lang(jenaLang) + .labelToNode(LabelToNode.createUseLabelAsGiven()) + .parse(jellyWriter) jellyWriter.finish() /** Convert Jelly text to Jelly binary. diff --git a/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala b/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala index 129b2c0..c6cf447 100644 --- a/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala +++ b/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala @@ -78,6 +78,25 @@ class RdfToJellySpec extends AnyWordSpec with TestFixtureHelper with Matchers: content.containsAll(tripleModel.listStatements()) shouldBe true } + "preserve the original blank node IDs" in { + val inputString = + """_:b1 _:b2 . + |_:b1 _:b3 . + |""".stripMargin + val input = ByteArrayInputStream(inputString.getBytes) + RdfToJelly.setStdIn(input) + val (out, err) = RdfToJelly.runTestCommand( + List("rdf", "to-jelly", "--in-format", RdfFormat.NQuads.cliOptions.head), + ) + val newIn = new ByteArrayInputStream(RdfToJelly.getOutBytes) + val content = translateJellyBack(newIn) + content.size() should be(2) + val statements = content.listStatements().asScala.toSeq + statements.flatMap(s => Seq(s.getSubject, s.getObject)).toSet + .map(_.asResource().getId.toString) + .toSet should be(Set("b1", "b2", "b3")) + } + "input stream to output stream, generalized RDF (N-Triples)" in { val inputStream = new FileInputStream(getClass.getResource("/generalized.nt").getPath) RdfToJelly.setStdIn(inputStream)