Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://a.com/p> _:b2 .
|_:b1 <http://a.com/p> _: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)
Expand Down