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 @@ -8,7 +8,7 @@ import eu.neverblink.jelly.cli.util.io.IoUtil
import eu.neverblink.jelly.cli.util.jena.*
import eu.ostrzyciel.jelly.convert.jena.JenaConverterFactory
import eu.ostrzyciel.jelly.core.JellyOptions
import eu.ostrzyciel.jelly.core.proto.v1.RdfStreamFrame
import eu.ostrzyciel.jelly.core.proto.v1.{RdfStreamFrame, RdfStreamOptions}
import org.apache.jena.graph.Triple
import org.apache.jena.riot.RDFParser
import org.apache.jena.riot.system.StreamRDFLib
Expand Down Expand Up @@ -92,10 +92,10 @@ object RdfValidate extends JellyCommand[RdfValidateOptions]:
// Step 1: Validate delimiting
validateDelimiting(delimiting, delimited)
// Step 2: Validate basic stream structure & the stream options
val framesSeq = skipEmptyFrames(frameIterator.toSeq)
validateOptions(framesSeq)
val framesSeq = frameIterator.toSeq
val streamOptions = validateOptions(skipEmptyFrames(framesSeq))
// Step 3: Validate the content
validateContent(framesSeq, frameIndices, rdfComparison)
validateContent(framesSeq, frameIndices, rdfComparison, streamOptions)

private def validateDelimiting(
expected: Delimiting,
Expand All @@ -109,7 +109,7 @@ object RdfValidate extends JellyCommand[RdfValidateOptions]:
if delimited then
throw CriticalException("Expected undelimited input, but the file was delimited")

private def validateOptions(frames: Seq[RdfStreamFrame]): Unit =
private def validateOptions(frames: Seq[RdfStreamFrame]): RdfStreamOptions =
if !frames.head.rows.head.row.isOptions then
throw CriticalException("First row in the input stream does not contain stream options")
val streamOptions = frames.head.rows.head.row.options
Expand All @@ -134,17 +134,18 @@ object RdfValidate extends JellyCommand[RdfValidateOptions]:
streamOptions,
expectedOptions.getOrElse(JellyOptions.defaultSupportedOptions),
)
streamOptions

private def validateContent(
frames: Seq[RdfStreamFrame],
frameIndices: IndexRange,
maybeRdfComparison: Option[StreamRdfCollector],
opt: RdfStreamOptions,
): Unit =
// Prepare data structures
val jellyStreamConsumer =
if maybeRdfComparison.isDefined then StreamRdfCollector()
else StreamRDFLib.sinkNull()
val opt = frames.head.rows.head.row.options
val dec = JenaConverterFactory.anyStatementDecoder(
None,
(prefix, iri) => jellyStreamConsumer.prefix(prefix, iri.getURI),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,36 @@ class RdfValidateSpec extends AnyWordSpec, Matchers, TestFixtureHelper:
}
}

"content matches the reference RDF file, empty frames in the stream, sliced comparison" in withFullJenaFile {
jenaF =>
withEmptyJenaFile { emptyJenaF =>
withFullJellyFile { jellyF =>
// Three empty frames and the start and end
val input =
Array[Byte](0, 0, 0) ++ FileInputStream(jellyF).readAllBytes() ++ Array[Byte](
0,
0,
0,
)
val params = Seq(
(jenaF, "3"),
(emptyJenaF, "0..=2"),
(emptyJenaF, "4..=6"),
)
for (comparisonFile, frameIndices) <- params do
RdfValidate.setStdIn(ByteArrayInputStream(input))
RdfValidate.runTestCommand(
List(
"rdf",
"validate",
"--compare-to-rdf-file=" + comparisonFile,
"--compare-frame-indices=" + frameIndices,
),
)
}
}
}

"content matches the reference RDF file, using a slice of the stream" in withFullJenaFile {
jenaF =>
withFullJellyFile { jellyF =>
Expand Down