Skip to content

Commit

Permalink
Add support for the RDF-star stream option (#28)
Browse files Browse the repository at this point in the history
Closes: #26
  • Loading branch information
Ostrzyciel authored Sep 16, 2023
1 parent abca7ae commit e006d10
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/main/protobuf_shared
Submodule protobuf_shared updated 1 files
+2 −0 rdf.proto
16 changes: 16 additions & 0 deletions core/src/main/scala/eu/ostrzyciel/jelly/core/JellyOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ object JellyOptions:
def bigGeneralized: RdfStreamOptions =
bigStrict.withGeneralizedStatements(true)

/**
* "Big" preset suitable for high-volume streams and larger machines.
* Allows RDF-star statements.
* @return
*/
def bigRdfStar: RdfStreamOptions =
bigStrict.withRdfStar(true)

/**
* "Small" preset suitable for low-volume streams and smaller machines.
* Does not allow generalized RDF statements.
Expand All @@ -47,3 +55,11 @@ object JellyOptions:
*/
def smallGeneralized: RdfStreamOptions =
smallStrict.withGeneralizedStatements(true)

/**
* "Small" preset suitable for low-volume streams and smaller machines.
* Allows RDF-star statements.
* @return
*/
def smallRdfStar: RdfStreamOptions =
smallStrict.withRdfStar(true)
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class IoSerDesSpec extends AnyWordSpec, Matchers, ScalaFutures:

val presets: Seq[(RdfStreamOptions, Int, String)] = Seq(
(JellyOptions.smallGeneralized, 1, "small generalized"),
(JellyOptions.smallGeneralized, 1_000_000, "small generalized"),
(JellyOptions.smallRdfStar, 1_000_000, "small RDF-star"),
(JellyOptions.smallStrict, 30, "small strict"),
(JellyOptions.bigGeneralized, 256, "big generalized"),
(JellyOptions.bigRdfStar, 10_000, "big RDF-star"),
(JellyOptions.bigStrict, 3, "big strict"),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ final class JellyFormatVariant(
object JellyFormat:
val JELLY_SMALL_STRICT = new RDFFormat(JELLY, JellyFormatVariant(JellyOptions.smallStrict))
val JELLY_SMALL_GENERALIZED = new RDFFormat(JELLY, JellyFormatVariant(JellyOptions.smallGeneralized))
val JELLY_SMALL_RDF_STAR = new RDFFormat(JELLY, JellyFormatVariant(JellyOptions.smallRdfStar))
val JELLY_BIG_STRICT = new RDFFormat(JELLY, JellyFormatVariant(JellyOptions.bigStrict))
val JELLY_BIG_GENERALIZED = new RDFFormat(JELLY, JellyFormatVariant(JellyOptions.bigGeneralized))
val JELLY_BIG_RDF_STAR = new RDFFormat(JELLY, JellyFormatVariant(JellyOptions.bigRdfStar))

val allFormats = List(
JELLY_SMALL_STRICT,
JELLY_SMALL_GENERALIZED,
JELLY_SMALL_RDF_STAR,
JELLY_BIG_STRICT,
JELLY_BIG_GENERALIZED
JELLY_BIG_GENERALIZED,
JELLY_BIG_RDF_STAR
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object JellyLanguage:
RDFLanguages.register(JELLY)

// Default serialization format
RDFWriterRegistry.register(JELLY, JellyFormat.JELLY_SMALL_GENERALIZED)
RDFWriterRegistry.register(JELLY, JellyFormat.JELLY_SMALL_STRICT)
// Register the writers
for format <- JellyFormat.allFormats do
RDFWriterRegistry.register(format, JellyGraphWriterFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class JellyWriter(out: OutputStream) extends AbstractRDFWriter:
s.add(STREAM_TYPE)
s.add(ALLOW_GENERALIZED_STATEMENTS)
s.add(USE_REPEAT)
s.add(ALLOW_RDF_STAR)
s.add(MAX_NAME_TABLE_SIZE)
s.add(MAX_PREFIX_TABLE_SIZE)
s.add(MAX_DATATYPE_TABLE_SIZE)
Expand All @@ -42,6 +43,7 @@ final class JellyWriter(out: OutputStream) extends AbstractRDFWriter:
streamType = c.get(STREAM_TYPE),
generalizedStatements = c.get(ALLOW_GENERALIZED_STATEMENTS).booleanValue(),
useRepeat = c.get(USE_REPEAT).booleanValue(),
rdfStar = c.get(ALLOW_RDF_STAR).booleanValue(),
maxNameTableSize = c.get(MAX_NAME_TABLE_SIZE).toInt,
maxPrefixTableSize = c.get(MAX_PREFIX_TABLE_SIZE).toInt,
maxDatatypeTableSize = c.get(MAX_DATATYPE_TABLE_SIZE).toInt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ object JellyWriterSettings:
"Whether to compress repeating values (recommended)",
true
)

val ALLOW_RDF_STAR = new BooleanRioSetting(
"eu.ostrzyciel.jelly.convert.rdf4j.rio.allowRdfStar",
"Allow RDF-star statements",
false
)

val MAX_NAME_TABLE_SIZE = new LongRioSetting(
"eu.ostrzyciel.jelly.convert.rdf4j.rio.maxNameTableSize",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object JellyOptionsFromTypesafe:
|stream-type = UNSPECIFIED
|generalized-statements = false
|use-repeat = true
|rdf-star = false
|name-table-size = 128
|prefix-table-size = 16
|dt-table-size = 16
Expand All @@ -25,6 +26,7 @@ object JellyOptionsFromTypesafe:
* - "stream-type", either UNSPECIFIED, TRIPLES, QUADS, or GRAPHS. Default: UNSPECIFIED.
* - "generalized-statements", boolean. Default: false.
* - "use-repeat", boolean. Default: true.
* - "rdf-star", boolean. Default: false.
* - "name-table-size", integer. Default: 128.
* - "prefix-table-size", integer. Default: 16.
* - "dt-table-size", integer. Default: 16.
Expand All @@ -43,6 +45,7 @@ object JellyOptionsFromTypesafe:
),
generalizedStatements = merged.getBoolean("generalized-statements"),
useRepeat = merged.getBoolean("use-repeat"),
rdfStar = merged.getBoolean("rdf-star"),
maxNameTableSize = merged.getInt("name-table-size"),
maxPrefixTableSize = merged.getInt("prefix-table-size"),
maxDatatypeTableSize = merged.getInt("dt-table-size"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JellyOptionsFromTypesafeSpec extends AnyWordSpec, Matchers:
|jelly.stream-type = GRAPHS
|jelly.generalized-statements = true
|jelly.use-repeat = false
|jelly.rdf-star = true
|jelly.name-table-size = 1024
|jelly.prefix-table-size = 64
|jelly.dt-table-size = 8
Expand All @@ -30,6 +31,7 @@ class JellyOptionsFromTypesafeSpec extends AnyWordSpec, Matchers:
opt.streamType should be (RdfStreamType.RDF_STREAM_TYPE_GRAPHS)
opt.generalizedStatements should be (true)
opt.useRepeat should be (false)
opt.rdfStar should be (true)
opt.maxNameTableSize should be (1024)
opt.maxPrefixTableSize should be (64)
opt.maxDatatypeTableSize should be (8)
Expand All @@ -45,6 +47,7 @@ class JellyOptionsFromTypesafeSpec extends AnyWordSpec, Matchers:
opt.streamType should be (RdfStreamType.RDF_STREAM_TYPE_QUADS)
opt.generalizedStatements should be (false)
opt.useRepeat should be (true)
opt.rdfStar should be (false)
opt.maxNameTableSize should be (1024)
opt.maxPrefixTableSize should be (64)
opt.maxDatatypeTableSize should be (16)
Expand Down

0 comments on commit e006d10

Please sign in to comment.