forked from Jelly-RDF/jelly-jvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jena & RDF4J: autodetect if parsed file is delimited or not (Jelly-RD…
…F#185) * Jena & RDF4J: autodetect if parsed file is delimited or not Continuation of Jelly-RDF#184. On top of support for this functionality in Jena, I've added the same for RDF4J and added a bunch of integration tests.
- Loading branch information
1 parent
7acae0c
commit 2016a47
Showing
9 changed files
with
98 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...n-tests/src/test/scala/eu/ostrzyciel/jelly/integration_tests/io/NonDelimitedDesSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package eu.ostrzyciel.jelly.integration_tests.io | ||
|
||
import eu.ostrzyciel.jelly.convert.jena.JenaConverterFactory | ||
import eu.ostrzyciel.jelly.core.JellyOptions | ||
import eu.ostrzyciel.jelly.core.proto.v1.* | ||
import eu.ostrzyciel.jelly.integration_tests.TestCases | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
import java.io.{ByteArrayInputStream, FileInputStream} | ||
import scala.jdk.CollectionConverters.* | ||
|
||
/** | ||
* Test checking if the delimited/non-delimited auto-detection works correctly. | ||
* | ||
* This test only contains non-delimited tests. For the delimited ones, see: | ||
* [[eu.ostrzyciel.jelly.integration_tests.io.IoSerDesSpec]]. | ||
* More fine-grained tests for delimited/non-delimited detection can be found in the jelly-core module. | ||
*/ | ||
class NonDelimitedDesSpec extends AnyWordSpec, Matchers: | ||
|
||
val presets: Seq[(RdfStreamOptions, String)] = Seq( | ||
(JellyOptions.smallGeneralized, "small generalized"), | ||
(JellyOptions.bigGeneralized, "big generalized"), | ||
).map( | ||
(opt, name) => (opt.copy(physicalType = PhysicalStreamType.TRIPLES), name) | ||
) | ||
|
||
val methods = Seq( | ||
(JenaSerDes, "Jena RIOT"), | ||
(Rdf4jSerDes, "RDF4J Rio"), | ||
) | ||
|
||
for (caseName, file) <- TestCases.triples do | ||
val model = JenaSerDes.readTriplesW3C(new FileInputStream(file)) | ||
val originalSize = model.size() | ||
for preset <- presets do | ||
val (options, presetName) = preset | ||
val encoder = JenaConverterFactory.encoder(options) | ||
val rows = model.getGraph.find().asScala.flatMap(encoder.addTripleStatement).toSeq | ||
val frame = RdfStreamFrame(rows) | ||
val bytes = frame.toByteArray | ||
|
||
runTest(JenaSerDes, "Jena RIOT") | ||
runTest(Rdf4jSerDes, "RDF4J Rio") | ||
|
||
def runTest[TMDes: Measure](method: NativeSerDes[TMDes, ?], methodName: String) = | ||
f"$methodName" should { | ||
f"deserialize non-delimited triples from $presetName ($caseName)" in { | ||
val deserialized = method.readTriplesJelly(new ByteArrayInputStream(bytes), None) | ||
summon[Measure[TMDes]].size(deserialized) shouldEqual originalSize | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters