aboutsummaryrefslogtreecommitdiff
path: root/lib/core/literal.ml
blob: fbff07b78d6bfa2352ee4b2df804d0b4df740142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(*
 * 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

let equal a b =
  (String.equal a.value b.value)
  &&
  (Iri.equal a.datatype b.datatype)
  &&
  (Option.equal String.equal a.language b.language)

let compare a b =
  String.compare
    (Iri.to_string a.datatype ^ canonical a ^
     (Option.value ~default:"" a.language))
    (Iri.to_string b.datatype ^ canonical b ^
     (Option.value ~default:"" b.language))

let pp ppf literal =
  (* TODO print language. Maybe use the Turtle pp for nicer pp. *)
  Fmt.pf ppf "@[<h 1><literal@ %s^^%a>@]"
    (canonical literal)
    Iri.pp (datatype literal)