Low-level usage
Warning
This page describes a low-level API that is a bit of a hassle to use directly. It's recommended to use the higher-level abstractions provided by the jelly-stream module, or the integrations with Apache Jena's RIOT or RDF4J's Rio libraries. If you really want to use this, it is highly recommended that you first get a basic understanding of how Jelly works under the hood and take a look at the code in the jelly-stream module to see how it's done there.
Note
The following guide uses the Apache Jena library as an example. The exact same thing can be done with RDF4J or any other RDF library that has a Jelly integration.
Deserialization
To parse a serialized stream frame into triples/quads:
- Call
eu.ostrzyciel.jelly.core.proto.v1.RdfStreamFrame.parseFromif it's a non-delimited frame (like you would see, e.g., in a Kafka or gRPC stream), orparseDelimitedFromif it's a delimited stream (like you would see in a file or a socket).- There is also a utility method to detect if the stream is delimited or not:
eu.ostrzyciel.jelly.core.IoUtils.autodetectDelimiting. In most cases you will not need to use it. It is used internally by the Jena and RDF4J integrations for user convenience.
- There is also a utility method to detect if the stream is delimited or not:
- Obtain a decoder that turns
RdfStreamFrames into triples/quads:eu.ostrzyciel.jelly.convert.jena.JenaConverterFactoryhas different methods for different physical stream types:anyStatementDecoderfor any physical stream type, outputsTripleorQuadtriplesDecoderfor TRIPLES streams, outputsTriplequadsDecoderfor QUADS streams, outputsQuadgraphsDecoderfor GRAPHS streams, outputs(Node, Iterable[Triple])graphsAsQuadsDecoderfor GRAPHS streams, outputsQuad
- For each row in the frame, call the decoder's
ingestRowmethod to get the output iteratively.
Serialization
To serialize triples/quads into a stream frame:
- If you want to serialize an RDF graph/dataset, transform them first into triples/quads in an iterable form. Use the
asTriples/asQuads/asGraphsextension methods provided by theeu.ostrzyciel.jelly.convert.jena.JenaIterableAdapterobject. - Obtain an encoder that turns triples/quads into
RdfStreamRows (the rows of a stream frame): use theeu.ostrzyciel.jelly.convert.jena.JenaConverterFactory.encodermethod to get an instance ofeu.ostrzyciel.jelly.convert.jena.JenaProtoEncoder. - Call the encoder's methods to add quads, triples, or named graphs to the stream frame.
- Note that YOU are responsible for sticking to a specific physical stream type. For example, you should not mix triples with quads. It is highly recommended that you first read on the available stream types in Jelly.
- You are also responsible for setting the appropriate stream options with proper stream types. See the guide on Jelly options presets for more information.
- The encoder will be returning batches or rows. You are responsible for grouping those rows logically into
RdfStreamFrames. What you do here depends highly on the logical stream type you are working with.