aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-05-19 13:47:29 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:01:35 +0200
commita50159bc8aa826b5263f76322e97c9522e09f5b4 (patch)
tree69a2eea28e459342b5976b7dd01dfbef1c3d97ec
parentb218a2e77f070dacb984f033e5ed27413d7a933c (diff)
Rdf_turtle:
add turtle types, following the turtle grammar from https://www.w3.org/TR/turtle/#literals. It is in some places different from this grammar, where simplifications where needed. We don't use the Rdf_core types, except from Iri's. Maybe this is still possible (for example in the case of predicates). It needs some organization to make it more similar to the rdf_core lib, I suppose. It is based on zoggy, but he deviates more from the grammar (although with the same result, AFAICS).
-rw-r--r--lib/turtle/dune3
-rw-r--r--lib/turtle/rdf_turtle.ml62
-rw-r--r--lib/turtle/rdf_turtle.mli65
3 files changed, 130 insertions, 0 deletions
diff --git a/lib/turtle/dune b/lib/turtle/dune
new file mode 100644
index 0000000..b0e54f1
--- /dev/null
+++ b/lib/turtle/dune
@@ -0,0 +1,3 @@
+(library
+ (name rdf_turtle)
+ (libraries rdf))
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
new file mode 100644
index 0000000..c9ba771
--- /dev/null
+++ b/lib/turtle/rdf_turtle.ml
@@ -0,0 +1,62 @@
+(*
+* SPDX-FileCopyrightText: 2021 alleycat <info@alleycat.cc>
+* SPDX-FileCopyrightText: 2021 petites singularit├ęs <ps-dream@lesoiseaux.io>
+* SPDX-FileCopyrightText: 2021 pukkamustard <pukkamustard@posteo.net>
+*
+* SPDX-License-Identifier: AGPL-3.0-or-later
+*)
+
+module Iri = Rdf.Iri
+
+module Ordered_string = struct
+ type t = string
+ let compare = String.compare
+end
+
+module SMap = Map.Make (Ordered_string)
+
+type iriref = string
+type language = string
+
+type prefixed_name = string option * string option
+type blank_node = Blank_node of string
+
+type iri = Iriref of iriref | Prefixed_name of prefixed_name
+
+type literal = String of string * language option * iri option
+
+type predicate = Pred_iri of iri | Pred_a
+
+type object' =
+ Obj_iri of iri
+ | Obj_blank_node of blank_node
+ | Obj_literal of literal
+ | Obj_coll of collection
+ | Obj_BnodPs of bnodep list
+and collection =
+ Collection of object' list
+and subject =
+ Sub_iri of iri
+ | Sub_blank_node of blank_node
+ | Sub_coll of collection
+and bnodep = BNodeP of predobj
+and predobj = predicate * object' list
+
+type triples =
+ SubjPredObjs of (subject * predobj list)
+ | BNodePs of (bnodep list)
+
+type directive = PrefixID of string * iriref | Base of iriref
+
+type statement = Directive of directive | Triples of triples
+
+type turtle = statement list
+
+type parser_state = {
+ base_uri : Iri.t;
+ namespaces : Iri.t SMap.t;
+ bnode_labels : blank_node SMap.t;
+ cur_subject: subject;
+ cur_predicate: predicate;
+}
+
diff --git a/lib/turtle/rdf_turtle.mli b/lib/turtle/rdf_turtle.mli
new file mode 100644
index 0000000..64f80df
--- /dev/null
+++ b/lib/turtle/rdf_turtle.mli
@@ -0,0 +1,65 @@
+(*
+* SPDX-FileCopyrightText: 2021 alleycat <info@alleycat.cc>
+* SPDX-FileCopyrightText: 2021 petites singularit├ęs <ps-dream@lesoiseaux.io>
+* SPDX-FileCopyrightText: 2021 pukkamustard <pukkamustard@posteo.net>
+*
+* SPDX-License-Identifier: AGPL-3.0-or-later
+*)
+
+module Iri = Rdf.Iri
+
+module SMap : Map.S with type key = string
+
+(* we take a string for an iri *)
+type iriref = string
+type language = string
+
+(* The prefixed name is given by a PNAME_NS and PNAME_LN *)
+(* This is the namespace and the local part *)
+type prefixed_name = string option * string option
+type blank_node = Blank_node of string
+
+type iri = Iriref of iriref | Prefixed_name of prefixed_name
+
+(* The language option indicates a language, the iri option inidicates the data type *)
+type literal = String of string * language option * iri option
+
+(* We omit the 'verb' type, since this predicate type encompasses the same space *)
+type predicate = Pred_iri of iri | Pred_a
+
+(* The types below are (recursive, what is it called?). The 'and' indicates this. *)
+type object' =
+ Obj_iri of iri
+ | Obj_blank_node of blank_node
+ | Obj_literal of literal
+ | Obj_coll of collection
+ | Obj_BnodPs of bnodep list
+and collection =
+ Collection of object' list
+and subject =
+ Sub_iri of iri
+ | Sub_blank_node of blank_node
+ | Sub_coll of collection
+and bnodep = BNodeP of predobj
+and predobj = predicate * object' list
+
+type triples =
+ SubjPredObjs of (subject * predobj list)
+ | BNodePs of (bnodep list)
+
+type directive = PrefixID of string * iriref | Base of iriref
+
+type statement = Directive of directive | Triples of triples
+
+type turtle = statement list
+
+(* Note that we more or less say: prefix = string *)
+(* What is the purpose of the bnode_labels map? *)
+type parser_state = {
+ base_uri : Iri.t;
+ namespaces : Iri.t SMap.t;
+ bnode_labels : blank_node SMap.t;
+ cur_subject: subject;
+ cur_predicate: predicate;
+}
+