From 3dac3590253504ecbff1d88ebb2941a344becc30 Mon Sep 17 00:00:00 2001 From: Henry Story Date: Thu, 18 Mar 2021 11:52:04 +0100 Subject: [PATCH] Add a comprehensive list of RDF Media Types --- build.sbt | 2 + .../scala/run/cosy/http/RDFMediaTypes.scala | 111 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/main/scala/run/cosy/http/RDFMediaTypes.scala diff --git a/build.sbt b/build.sbt index af49c7c..feaecc0 100644 --- a/build.sbt +++ b/build.sbt @@ -33,6 +33,8 @@ lazy val root = project "ch.qos.logback" % "logback-classic" % "1.2.3", "org.typelevel" %% "cats-core" % "2.4.2", "org.typelevel" %% "cats-free" % "2.4.2", + "net.bblfish.rdf" %% "banana-rdf" % "0.8.5-SNAPSHOT", + "net.bblfish.rdf" %% "banana-jena" % "0.8.5-SNAPSHOT", //"com.novocode" % "junit-interface" % "0.11" % "test" ).map(_.withDottyCompat(scalaVersion.value)), diff --git a/src/main/scala/run/cosy/http/RDFMediaTypes.scala b/src/main/scala/run/cosy/http/RDFMediaTypes.scala new file mode 100644 index 0000000..4ca33b0 --- /dev/null +++ b/src/main/scala/run/cosy/http/RDFMediaTypes.scala @@ -0,0 +1,111 @@ +package run.cosy.http + +/** + * Media Types for RDF. + * Collected from the [[https://docs.aws.amazon.com/neptune/latest/userguide/sparql-media-type-support.html RDF media types used by SPARQL in Neptune]] document by Amazon. + * Feel free to complete the list if needed. + **/ +object RDFMediaTypes { + + import akka.http.scaladsl.model.MediaType + import akka.http.scaladsl.model.HttpCharsets.{`UTF-8`,`US-ASCII`} + + /** see [[https://www.w3.org/TR/rdf-syntax-grammar/#section-MIME-Type RDF1.1 XML Syntax]] spec and + * [[https://tools.ietf.org/html/rfc3870 RFC3870]] registration + **/ + val `application/rdf+xml` = MediaType.customWithOpenCharset( + "application","rdf+xml", + fileExtensions = List("rdf") + ) + + // Note that around 2004 the W3C defined a procedure for Mime Type Registration + // that uses the W3C specs without needing to go through an RFC procedure + // see [[https://www.w3.org/2020/01/registering-mediatypes.html Register and Internet Media Types for a W3C Spec]] + + /** see [[https://www.w3.org/TR/n-triples/#n-triples-mediatype RDF 1.1 N-Triples]] spec. */ + val `application/n-triples` = MediaType.customWithFixedCharset( + "application","n-triples",`UTF-8`, + fileExtensions = List("nt") + ) + /** + * see [[https://www.w3.org/TR/n-quads/#sec-mediatype W3C NQuads Speec]] + * has IRI: http://www.w3.org/ns/formats/N-Quads + */ + val `application/n-quads` = MediaType.customWithFixedCharset( + "application","n-quads",`UTF-8`, + fileExtensions = List("nq") + ) + + /** The older version of n-quads was limited to US-ASCII and had a different mime type */ + val `text/n-quads` = MediaType.customWithFixedCharset( + "text","n-quads",`US-ASCII`, + fileExtensions = List("nq") + ) + + /** + * see [[https://www.w3.org/TR/turtle/ RDF 1.1 Turtle]] + * has URI: http://www.w3.org/ns/formats/Turtle + */ + val `text/turtle` = MediaType.customWithFixedCharset( + "text","turtle",`UTF-8`, + fileExtensions = List("ttl") + ) + + /** + * see [[https://www.w3.org/TR/trig/#sec-mediaReg RDF1.1 TriG]] + */ + val `application/trig` = MediaType.customWithFixedCharset( + "application", "trig", `UTF-8`, + fileExtensions = List("trig") + ) + + /** + * see [[https://www.w3.org/TeamSubmission/n3/#sec-mediaReg Notation3 (N3): A readable RDF syntax]] + */ + val `text/n3` = MediaType.customWithFixedCharset( + "text","n3", `UTF-8`, + fileExtensions = "n3", + params = + ) + /** + * see [[https://www.w3.org/TR/json-ld/#application-ld-json JSON-LD 1.1]] + * The JSON-LD spec defined six values for a profile parameter listed next. + */ + val `application/ld+json` = MediaType.customWithFixedCharset( + "application","ld+json",`UTF-8`, + fileExtensions = List("jsonld") + ) + + val jsonLdExpandedProfile = Uri("http://www.w3.org/ns/json-ld#expanded") + val jsonLdCompactedProfile = Uri("http://www.w3.org/ns/json-ld#compacted") + val jsonLdContextProfile = Uri("http://www.w3.org/ns/json-ld#context") + val jsonLdFlattenedProfile = Uri("http://www.w3.org/ns/json-ld#flattened") + val jsonLdFrameProfile = Uri("http://www.w3.org/ns/json-ld#frame") + val jsonLdFramedProfile = Uri("http://www.w3.org/ns/json-ld#framed") + + /** + * Quad format defined by HP in XML + * [[https://www.hpl.hp.com/techreports/2004/HPL-2004-56.html]] + */ + val `application/trix` = MediaType.customWithOpenCharset( + "application","trix", + fileExtensions = List("trix") + ) + + /** + * see [[https://www.w3.org/TR/sparql11-results-json/#content-type SPARQL 1.1 Query Results JSON Format]] + */ + val `application/sparql-results+json` = MediaType.customWithFixedCharset( + "application","sparql-results+json",`UTF-8`, + fileExtensions = List("srj") + ) + + /** + * see [[https://www.w3.org/TR/rdf-sparql-XMLres/#mime SPARQL Query Results XML Format (Second Edition)]] + */ + val `application/sparql-results+xml` = MediaType.customWithOpenCharset( + "application","sparql-results+xml", + fileExtensions = List("srx") + ) + +}