support for RDF/XML representation;
authorwenzelm
Thu Feb 14 15:46:38 2019 +0100 (17 months ago)
changeset 698073389fda6cffd
parent 69806 2156053c4ce9
child 69808 c64197a224c6
support for RDF/XML representation;
src/Pure/General/rdf.scala
src/Pure/build-jars
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/General/rdf.scala	Thu Feb 14 15:46:38 2019 +0100
     1.3 @@ -0,0 +1,42 @@
     1.4 +/*  Title:      Pure/General/rdf.scala
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Support for RDF/XML representation, see also:
     1.8 +  - https://www.w3.org/RDF
     1.9 +  - https://www.w3.org/TR/rdf-primer
    1.10 +*/
    1.11 +
    1.12 +package isabelle
    1.13 +
    1.14 +
    1.15 +object RDF
    1.16 +{
    1.17 +  /* document */
    1.18 +
    1.19 +  val rdf: XML.Namespace = XML.Namespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
    1.20 +  val dc: XML.Namespace = XML.Namespace("dc", "http://purl.org/dc/elements/1.1/")
    1.21 +
    1.22 +  val default_namespaces: List[XML.Namespace] = List(rdf, dc)
    1.23 +
    1.24 +  def document(body: XML.Body,
    1.25 +    namespaces: List[XML.Namespace] = default_namespaces,
    1.26 +    attributes: XML.Attributes = Nil): XML.Elem =
    1.27 +  {
    1.28 +    XML.Elem(Markup(rdf("RDF"), namespaces.map(_.attribute) ::: attributes), body)
    1.29 +  }
    1.30 +
    1.31 +
    1.32 +  /* multiple triples vs. compact description */
    1.33 +
    1.34 +  sealed case class Triple(subject: String, predicate: String, `object`: XML.Body)
    1.35 +  {
    1.36 +    def property: XML.Elem = XML.elem(predicate, `object`)
    1.37 +  }
    1.38 +
    1.39 +  def triples(args: List[Triple]): XML.Body =
    1.40 +    args.groupBy(_.subject).toList.map(
    1.41 +      { case (subject, ts) => description(subject, ts.map(_.property)) })
    1.42 +
    1.43 +  def description(subject: String, body: XML.Body, attributes: XML.Attributes = Nil): XML.Elem =
    1.44 +    XML.Elem(Markup(rdf("Description"), (rdf("about"), subject) :: attributes), body)
    1.45 +}
     2.1 --- a/src/Pure/build-jars	Thu Feb 14 15:45:34 2019 +0100
     2.2 +++ b/src/Pure/build-jars	Thu Feb 14 15:46:38 2019 +0100
     2.3 @@ -65,6 +65,7 @@
     2.4    General/position.scala
     2.5    General/pretty.scala
     2.6    General/properties.scala
     2.7 +  General/rdf.scala
     2.8    General/scan.scala
     2.9    General/sha1.scala
    2.10    General/sql.scala