-
Notifications
You must be signed in to change notification settings - Fork 2
GH-93 Allow non streaming output formats in rdf from-jelly #148
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
Merged
niegrzybkowski
merged 12 commits into
main
from
GH-93/rdf-from-jelly-allow-non-streaming-output-formats
Jul 8, 2025
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f0f1a94
Add StreamRdfBatchSink as a fallback for non-streaming formats
niegrzybkowski 712cd08
Make jsonld and rdfxml formats use StreamRdfBatchSink
niegrzybkowski 7bfdce3
Add tests for jsonld and rdfxml output conversions
niegrzybkowski ece12d1
Remove test for unwriteable formats
niegrzybkowski 21ba743
Rename RdfFormat.Jena.Writeable to RdfFormat.Jena.StreamWriteable
niegrzybkowski e9847e5
Rename StreamRdfBatchSink to StreamRdfBatchWriter
niegrzybkowski 1b040a6
Replace Model with Dataset in StreamRdfBatchWriter
niegrzybkowski 54037c3
Add support for combining frames
niegrzybkowski 517bdb4
Add tests for Dataset handling, frame handling, and frame combining.
niegrzybkowski 0dd13a2
Merge branch 'main' into GH-93/rdf-from-jelly-allow-non-streaming-out…
niegrzybkowski 19767a2
Doc corrections
niegrzybkowski 3cc5fb7
Disable RDF/XML multi-model test
niegrzybkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
src/main/scala/eu/neverblink/jelly/cli/util/jena/StreamRdfBatchWriter.scala
This file contains hidden or 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,36 @@ | ||
| package eu.neverblink.jelly.cli.util.jena | ||
|
|
||
| import org.apache.jena.riot.system.StreamRDF | ||
| import org.apache.jena.sparql.core.Quad | ||
| import org.apache.jena.graph.Triple | ||
| import org.apache.jena.riot.system.StreamRDFLib | ||
| import java.io.OutputStream | ||
| import org.apache.jena.riot.Lang | ||
| import org.apache.jena.riot.RDFDataMgr | ||
| import org.apache.jena.query.DatasetFactory | ||
| import org.apache.jena.query.Dataset | ||
|
|
||
| /** A StreamRDF implementation that collects everything into a Model. When finishing, formats | ||
| * everything according to the lang, and emits it to the outputStream. This is meant to be a | ||
| * fallback for non-streaming RDF formats, as it requires all data to be loaded in memory. | ||
| */ | ||
| class StreamRdfBatchWriter(val outputStream: OutputStream, val lang: Lang) extends StreamRDF: | ||
| protected val dataset: Dataset = DatasetFactory.create() | ||
| protected val datasetStream: StreamRDF = StreamRDFLib.dataset(dataset.asDatasetGraph()) | ||
| override def quad(quad: Quad): Unit = datasetStream.quad(quad) | ||
| override def triple(triple: Triple): Unit = datasetStream.triple(triple) | ||
| override def prefix(prefix: String, iri: String): Unit = datasetStream.prefix(prefix, iri) | ||
| override def base(base: String): Unit = datasetStream.base(base) | ||
| override def finish(): Unit = writeOutput() | ||
| override def start(): Unit = () | ||
| def writeOutput(): Unit = | ||
| if lang == Lang.RDFXML then RDFDataMgr.write(outputStream, dataset.getDefaultModel, lang) | ||
| else RDFDataMgr.write(outputStream, dataset, lang) | ||
| def runAndOutput(runnable: StreamRDF => Unit): Unit = { | ||
| runnable(this) | ||
| writeOutput() | ||
| } | ||
|
|
||
| class StreamRdfCombiningBatchWriter(outputStream: OutputStream, lang: Lang) | ||
| extends StreamRdfBatchWriter(outputStream, lang): | ||
| override def finish(): Unit = () |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.