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

Fix missing phys. stream type in RDF4J writer #220

Merged
merged 1 commit into from
Nov 14, 2024
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 @@ -45,12 +45,10 @@ object Rdf4jSerDes extends NativeSerDes[Seq[Statement], Seq[Statement]]:
writer.endRDF()

override def writeTriplesJelly(os: OutputStream, model: Seq[Statement], opt: RdfStreamOptions, frameSize: Int): Unit =
// We set the physical type to TRIPLES, because the writer has no way of telling triples from
// quads in RDF4J. Thus, the writer will default to QUADS.
write(os, model, opt.withPhysicalType(PhysicalStreamType.TRIPLES), frameSize)

override def writeQuadsJelly(os: OutputStream, dataset: Seq[Statement], opt: RdfStreamOptions, frameSize: Int): Unit =
write(os, dataset, opt.withPhysicalType(PhysicalStreamType.QUADS), frameSize)





// No need to set the physical type, because the writer will default to QUADS.
write(os, dataset, opt, frameSize)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.ostrzyciel.jelly.convert.rdf4j.rio

import eu.ostrzyciel.jelly.convert.rdf4j.Rdf4jProtoEncoder
import eu.ostrzyciel.jelly.core.proto.v1.{LogicalStreamType, RdfStreamFrame, RdfStreamOptions, RdfStreamRow}
import eu.ostrzyciel.jelly.core.proto.v1.*
import org.eclipse.rdf4j.model.Statement
import org.eclipse.rdf4j.rio.{RDFFormat, RioSetting}
import org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
Expand All @@ -10,7 +10,15 @@ import java.io.OutputStream
import java.util
import scala.collection.mutable.ArrayBuffer

//noinspection ConvertNullInitializerToUnderscore
/**
* RDF4J Rio writer for Jelly RDF format.
*
* The writer will automatically set the logical stream type based on the physical stream type.
* If no physical stream type is set, it will default to quads, because we really have no way of knowing in RDF4J.
* If you want your stream to be really of type TRIPLES, set the PHYSICAL_TYPE setting yourself.
*
* @param out the output stream to write to
*/
final class JellyWriter(out: OutputStream) extends AbstractRDFWriter:
import JellyWriterSettings.*

Expand Down Expand Up @@ -38,7 +46,9 @@ final class JellyWriter(out: OutputStream) extends AbstractRDFWriter:
super.startRDF()

val c = getWriterConfig
val pType = c.get(PHYSICAL_TYPE)
var pType = c.get(PHYSICAL_TYPE)
if pType.isUnspecified then
pType = PhysicalStreamType.QUADS
val lType = if pType.isTriples then
LogicalStreamType.FLAT_TRIPLES
else if pType.isQuads then
Expand All @@ -48,7 +58,7 @@ final class JellyWriter(out: OutputStream) extends AbstractRDFWriter:

options = RdfStreamOptions(
streamName = c.get(STREAM_NAME),
physicalType = c.get(PHYSICAL_TYPE),
physicalType = pType,
generalizedStatements = c.get(ALLOW_GENERALIZED_STATEMENTS).booleanValue(),
rdfStar = c.get(ALLOW_RDF_STAR).booleanValue(),
maxNameTableSize = c.get(MAX_NAME_TABLE_SIZE).toInt,
Expand Down