-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #51, #52 Implemented: - Physical & logical stream types in Jelly, where logical are directly from RDF-STaX - Logical types are implemented as an enum - Type numbers were picked such that the most common types (1, 2, 3, 4) are low, making the varint in the protobuf output smaller. - Type numbers signify taxonomical relations in RDF-STaX. 14 is a child of 4, and 114 is a child of 14. This makes the system forward compatible – current consumers will be able to interpret future subtypes as their parent types. - Support for logical types in streaming encoders/decoders - Automatic checks for logical type compatibility and logical-physical consistency (if a given stream is possible, can be consumed, etc.) - Emitting RDF-based annotations (metadata) about the logical type of the stream, using the RDF-STaX ontology. This uses the existing facilities of decoder converters.
- Loading branch information
1 parent
b232d84
commit 08fc666
Showing
31 changed files
with
1,087 additions
and
408 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package eu.ostrzyciel.jelly.core | ||
|
||
object Constants: | ||
val jellyName = "Jelly" | ||
val jellyFileExtension = "jelly" | ||
val jellyContentType = "application/x-jelly-rdf" | ||
val protoVersion = 1 | ||
val protoSemanticVersion = "1.0.0" |
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
16 changes: 7 additions & 9 deletions
16
...la/eu/ostrzyciel/jelly/core/package.scala → ...trzyciel/jelly/core/JellyExceptions.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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
package eu.ostrzyciel.jelly | ||
package eu.ostrzyciel.jelly.core | ||
|
||
package object core: | ||
private trait JellyExceptions: | ||
sealed class RdfProtoDeserializationError(msg: String) extends Error(msg) | ||
|
||
final class MissingPrefixEntryError(val prefixId: Int) extends RdfProtoDeserializationError( | ||
s"Missing entry in prefix table at ID: $prefixId" | ||
) | ||
|
||
final class MissingNameEntryError(val nameId: Int) extends RdfProtoDeserializationError( | ||
s"Missing entry in name table at ID: $nameId" | ||
) | ||
|
||
final class RdfProtoSerializationError(msg: String) extends Error(msg) | ||
|
||
private object JellyExceptions extends JellyExceptions | ||
|
||
// Constants | ||
object Constants: | ||
val jellyName = "Jelly" | ||
val jellyFileExtension = "jelly" | ||
val jellyContentType = "application/x-jelly-rdf" | ||
val protoVersion = 1 | ||
val protoSemanticVersion = "1.0.0" | ||
export JellyExceptions.* |
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
92 changes: 92 additions & 0 deletions
92
core/src/main/scala/eu/ostrzyciel/jelly/core/LogicalStreamTypeExtensions.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,92 @@ | ||
package eu.ostrzyciel.jelly.core | ||
|
||
import eu.ostrzyciel.jelly.core.proto.v1.LogicalStreamType | ||
|
||
import java.util.UUID | ||
|
||
private trait LogicalStreamTypeExtensions: | ||
val staxPrefix = "https://w3id.org/stax/ontology#" | ||
|
||
extension (logicalType: LogicalStreamType) | ||
/** | ||
* Converts the logical stream type to its base concrete stream type in RDF-STaX. | ||
* For example, [[LogicalStreamType.TIMESTAMPED_NAMED_GRAPHS]] will be converted to [[LogicalStreamType.DATASETS]]. | ||
* UNSPECIFIED values will be left as-is. | ||
* | ||
* @return base stream type | ||
*/ | ||
def toBaseType: LogicalStreamType = | ||
LogicalStreamType.fromValue(logicalType.value % 10) | ||
|
||
/** | ||
* Checks if the logical stream type is equal to or a subtype of the other logical stream type. | ||
* For example, [[LogicalStreamType.TIMESTAMPED_NAMED_GRAPHS]] is a subtype of [[LogicalStreamType.DATASETS]]. | ||
* | ||
* @param other the other logical stream type | ||
* @return true if the logical stream type is equal to or a subtype of the other logical stream type | ||
*/ | ||
def isEqualOrSubtypeOf(other: LogicalStreamType): Boolean = | ||
logicalType == other || logicalType.value.toString.endsWith(other.value.toString) | ||
|
||
/** | ||
* Returns the IRI of the RDF-STaX stream type individual for the logical stream type. | ||
* If the logical stream type is not supported or is not specified, None is returned. | ||
* | ||
* @return the IRI of the RDF-STaX stream type individual | ||
*/ | ||
def getRdfStaxType: Option[String] = | ||
logicalType match | ||
case LogicalStreamType.FLAT_TRIPLES => Some(s"${staxPrefix}flatTripleStream") | ||
case LogicalStreamType.FLAT_QUADS => Some(s"${staxPrefix}flatQuadStream") | ||
case LogicalStreamType.GRAPHS => Some(s"${staxPrefix}graphStream") | ||
case LogicalStreamType.SUBJECT_GRAPHS => Some(s"${staxPrefix}subjectGraphStream") | ||
case LogicalStreamType.DATASETS => Some(s"${staxPrefix}datasetStream") | ||
case LogicalStreamType.NAMED_GRAPHS => Some(s"${staxPrefix}namedGraphStream") | ||
case LogicalStreamType.TIMESTAMPED_NAMED_GRAPHS => Some(s"${staxPrefix}timestampedNamedGraphStream") | ||
case _ => None | ||
|
||
/** | ||
* Returns an RDF-STaX annotation for the logical stream type, in RDF. The annotation simply states that | ||
* <subjectNode> has a stream type usage, and that stream type usage has this stream type. | ||
* | ||
* Example in Turtle for a flat triple stream: | ||
* <subjectNode> stax:hasStreamTypeUsage [ | ||
* a stax:RdfStreamTypeUsage ; | ||
* stax:hasStreamType stax:flatTripleStream | ||
* ] . | ||
* | ||
* @param subjectNode the subject node to annotate | ||
* @param converterFactory the converter factory to use for creating RDF nodes and triples | ||
* @tparam TNode the type of RDF nodes | ||
* @tparam TTriple the type of RDF triples | ||
* @throws IllegalArgumentException if the logical stream type is not supported | ||
* @return the RDF-STaX annotation | ||
*/ | ||
def getRdfStaxAnnotation[TNode, TTriple](subjectNode: TNode) | ||
(using converterFactory: ConverterFactory[?, ?, TNode, ?, TTriple, ?]): Seq[TTriple] = | ||
getRdfStaxType match | ||
case Some(typeIri) => | ||
val converter = converterFactory.decoderConverter | ||
val bNode = converter.makeBlankNode(UUID.randomUUID().toString) | ||
Seq( | ||
converter.makeTriple( | ||
subjectNode, | ||
converter.makeIriNode(s"${staxPrefix}hasStreamTypeUsage"), | ||
bNode | ||
), | ||
converter.makeTriple( | ||
bNode, | ||
converter.makeIriNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), | ||
converter.makeIriNode(s"${staxPrefix}RdfStreamTypeUsage") | ||
), | ||
converter.makeTriple( | ||
bNode, | ||
converter.makeIriNode(s"${staxPrefix}hasStreamType"), | ||
converter.makeIriNode(typeIri) | ||
) | ||
) | ||
case None => throw new IllegalArgumentException(s"Unsupported logical stream type: $logicalType") | ||
|
||
private object LogicalStreamTypeExtensions extends LogicalStreamTypeExtensions | ||
|
||
export LogicalStreamTypeExtensions.* |
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
Oops, something went wrong.