aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2021-04-23 16:41:18 +0200
committerpukkamustard <pukkamustard@posteo.net>2021-04-23 16:41:18 +0200
commit5222f0c8b712fe764403752a8e1c5daedf48808e (patch)
tree85b44110ad48a6a713bf06df05e7a48ca3c58e7f
parentd7eb888ecb6c346d278d41e60335c7a1126ad5f7 (diff)
Rdf: Split out Literal and Blank_node to their own files.datalog
Also rename BlankNode to Blank_node.
-rw-r--r--lib/cbor/rdf_cbor.ml6
-rw-r--r--lib/core/blank_node.ml12
-rw-r--r--lib/core/literal.ml26
-rw-r--r--lib/core/rdf.ml4
-rw-r--r--lib/core/rdf.mli14
-rw-r--r--lib/core/term.ml37
-rw-r--r--lib/core/triple.ml5
-rw-r--r--lib/json/rdf_json.ml6
8 files changed, 58 insertions, 52 deletions
diff --git a/lib/cbor/rdf_cbor.ml b/lib/cbor/rdf_cbor.ml
index 3e8763a..17a7448 100644
--- a/lib/cbor/rdf_cbor.ml
+++ b/lib/cbor/rdf_cbor.ml
@@ -1,4 +1,4 @@
-module BlankNode = Rdf.BlankNode
+module Blank_node = Rdf.Blank_node
module Literal = Rdf.Literal
module Term = Rdf.Term
@@ -8,7 +8,7 @@ let cbor_of_iri iri =
let cbor_of_blank_node bnode =
Cbor.Tag (Z.of_int 300,
- Cbor.TextString (BlankNode.identifier bnode))
+ Cbor.TextString (Blank_node.identifier bnode))
let cbor_of_literal literal =
Cbor.Tag (Z.of_int 301,
@@ -43,7 +43,7 @@ let term_parser =
>>| Term.of_iri
else if Z.(equal z ~$300) then
any_text_string
- >>| BlankNode.of_string
+ >>| Blank_node.of_string
>>| Term.of_blank_node
else if Z.(equal z ~$301) then
tuple any_text_string iri_parser
diff --git a/lib/core/blank_node.ml b/lib/core/blank_node.ml
new file mode 100644
index 0000000..6c3b01e
--- /dev/null
+++ b/lib/core/blank_node.ml
@@ -0,0 +1,12 @@
+(*
+ * 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
+ *)
+
+type t = BNode of string
+
+let of_string id = BNode id
+
+let identifier (BNode id) = id
diff --git a/lib/core/literal.ml b/lib/core/literal.ml
new file mode 100644
index 0000000..08c826f
--- /dev/null
+++ b/lib/core/literal.ml
@@ -0,0 +1,26 @@
+(*
+ * 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 = Uri
+
+type t = {
+ value: string;
+ datatype: Iri.t;
+ language: string option;
+}
+
+let make value ?language datatype =
+ { value; datatype; language }
+
+let canonical literal =
+ literal.value
+
+let datatype literal =
+ literal.datatype
+
+let language literal =
+ literal.language
diff --git a/lib/core/rdf.ml b/lib/core/rdf.ml
index 3cb6070..37f923d 100644
--- a/lib/core/rdf.ml
+++ b/lib/core/rdf.ml
@@ -6,8 +6,8 @@
*)
module Iri = Term.Iri
-module BlankNode = Term.BlankNode
-module Literal = Term.Literal
+module Blank_node = Blank_node
+module Literal = Literal
module Term = Term
module Triple = Triple
diff --git a/lib/core/rdf.mli b/lib/core/rdf.mli
index 4477f56..dbcb36c 100644
--- a/lib/core/rdf.mli
+++ b/lib/core/rdf.mli
@@ -9,7 +9,7 @@
module Iri = Term.Iri
-module BlankNode : sig
+module Blank_node : sig
type t
(** A blank node. Don't use this. *)
@@ -46,13 +46,13 @@ module Term : sig
val of_iri : Iri.t -> t
(** [of_iri iri] casts the IRI [iri] to a term. *)
- val of_blank_node : BlankNode.t -> t
+ val of_blank_node : Blank_node.t -> t
(** [of_blank_node bnode] casts the Blank Node [bnode] to a term. *)
val of_literal : Literal.t -> t
(** [of_literal literal] casts the literal [literal] to a term. *)
- val map : t -> (Iri.t -> 'a) -> (BlankNode.t -> 'a) -> (Literal.t -> 'a) -> 'a
+ val map : t -> (Iri.t -> 'a) -> (Blank_node.t -> 'a) -> (Literal.t -> 'a) -> 'a
(** Map a term *)
end
@@ -72,10 +72,10 @@ module Triple : sig
val subject_of_iri : Iri.t -> subject
(** Create a subject from an Iri. *)
- val subject_of_blank_node : BlankNode.t -> subject
+ val subject_of_blank_node : Blank_node.t -> subject
(** Create a subject from a Blank Node*)
- val map_subject : subject -> (Iri.t -> 'a) -> (BlankNode.t -> 'a) -> 'a
+ val map_subject : subject -> (Iri.t -> 'a) -> (Blank_node.t -> 'a) -> 'a
(** [map_subject s f_iri f_bnode] maps the subject [s] by applying [f_iri] or
[f_bnode] depending on wheter subject is an IRI or blank node.*)
@@ -94,13 +94,13 @@ module Triple : sig
val object_of_iri : Iri.t -> object'
(** Create an object from an Iri.*)
- val object_of_blank_node : BlankNode.t -> subject
+ val object_of_blank_node : Blank_node.t -> subject
(** Create an object from a Blank Node.*)
val object_of_literal : Literal.t -> object'
(** Create an object from a literal*)
- val map_object : object' -> (Iri.t -> 'a) -> (BlankNode.t -> 'a) -> (Literal.t -> 'a) -> 'a
+ val map_object : object' -> (Iri.t -> 'a) -> (Blank_node.t -> 'a) -> (Literal.t -> 'a) -> 'a
(** Map an object *)
type t = {subject: subject; predicate: predicate; object': object'}
diff --git a/lib/core/term.ml b/lib/core/term.ml
index 364d03d..ef040d6 100644
--- a/lib/core/term.ml
+++ b/lib/core/term.ml
@@ -7,43 +7,12 @@
module Iri = Uri
-module BlankNode = struct
- type t = BNode of string
-
- let of_string id =
- BNode id
-
- let identifier (BNode id) =
- id
-end
-
-module Literal = struct
- type t = {
- value: string;
- datatype: Iri.t;
- language: string option;
- }
-
- let make value ?language datatype =
- { value; datatype; language }
-
- let canonical literal =
- literal.value
-
- let datatype literal =
- literal.datatype
-
- let language literal =
- literal.language
-end
-
-
(* This is a phantom type. This allows a RDF term to appear in different
contexts (as subject or as predicate) while keeping the exact same
representation.*)
type 'a internal =
| Iri of Iri.t
- | BlankNode of BlankNode.t
+ | Blank_node of Blank_node.t
| Literal of Literal.t
type any
@@ -51,11 +20,11 @@ type any
type t = any internal
let of_iri iri = Iri iri
-let of_blank_node bnode = BlankNode bnode
+let of_blank_node bnode = Blank_node bnode
let of_literal literal = Literal literal
let map = fun term f_iri f_blank_node f_literal ->
match term with
| Iri iri -> f_iri iri
- | BlankNode bnode -> f_blank_node bnode
+ | Blank_node bnode -> f_blank_node bnode
| Literal literal -> f_literal literal
diff --git a/lib/core/triple.ml b/lib/core/triple.ml
index 40055e1..7edf352 100644
--- a/lib/core/triple.ml
+++ b/lib/core/triple.ml
@@ -8,7 +8,7 @@
type c_subject
type subject = c_subject Term.internal
let subject_of_iri iri = Term.Iri iri
-let subject_of_blank_node bnode = Term.BlankNode bnode
+let subject_of_blank_node bnode = Term.Blank_node bnode
let map_subject s f_iri f_bnode =
Term.map s
@@ -31,12 +31,11 @@ let map_predicate p f =
type c_object
type object' = c_object Term.internal
let object_of_iri iri = Term.Iri iri
-let object_of_blank_node bnode = Term.BlankNode bnode
+let object_of_blank_node bnode = Term.Blank_node bnode
let object_of_literal literal = Term.Literal literal
let map_object = Term.map
-
type t = {subject: subject; predicate: predicate; object': object'}
let make subject predicate object' =
diff --git a/lib/json/rdf_json.ml b/lib/json/rdf_json.ml
index f8f31eb..3d9706c 100644
--- a/lib/json/rdf_json.ml
+++ b/lib/json/rdf_json.ml
@@ -1,7 +1,7 @@
module Triple = Rdf.Triple
module Term = Rdf.Term
module Iri = Rdf.Iri
-module BlankNode = Rdf.BlankNode
+module Blank_node = Rdf.Blank_node
module Literal = Rdf.Literal
(* TODO is this ok? There is List.sort_uniq, but that needs a compare function *)
@@ -24,7 +24,7 @@ let encode_subject : Triple.subject -> string =
Triple.map_subject s
(fun iri -> Uri.to_string iri)
(fun bnode ->
- "_:" ^ BlankNode.identifier bnode
+ "_:" ^ Blank_node.identifier bnode
)
let encode_predicate : Triple.predicate -> string =
@@ -46,7 +46,7 @@ let encode_object : Triple.object' -> Yojson.Basic.t =
`Assoc (
[ ( "type", `String "bnode" )
; ( "value" , `String (
- "_:" ^ BlankNode.identifier bnode)
+ "_:" ^ Blank_node.identifier bnode)
)
]
)