aboutsummaryrefslogtreecommitdiff
path: root/test/gen/rdf_gen.ml
blob: c4d3c41d0d93c04994774d7fb8a7196187ac14b3 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(*
 * 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 Blank_node = Rdf.Blank_node
module Literal = Rdf.Literal
module Term = Rdf.Term
module Triple = Rdf.Triple
module Subject = Triple.Subject
module Predicate = Triple.Predicate
module Object = Triple.Object
module Namespace = Rdf.Namespace

let iri =
  QCheck.Gen.(
    (fun scheme host -> Iri.make ~scheme ~host ())
    <$> (oneofl ["http"; "https"])
    <*> (oneofl ["example.com"; "test.com"; "dream.cat"]))
  |> QCheck.make ~print:Iri.to_string

let blank_node =
  QCheck.Gen.(
    Blank_node.of_string
    <$> string_readable)
  |> QCheck.make ~print:Blank_node.identifier

let literal =
  QCheck.Gen.(
    (fun s -> Literal.make s (Rdf.Namespace.xsd "string"))
    <$> string_readable
  )
  |> QCheck.make ~print:Literal.canonical

let term =
  QCheck.(
    [iri |> map Term.of_iri;
     blank_node |> map Term.of_blank_node;
     literal |> map Term.of_literal]
    |> choose)

let subject =
  QCheck.(
    [iri |> map (Subject.of_iri);
     blank_node |> map( Subject.of_blank_node);
    ]
    |> choose
  )

let predicate =
  iri |> QCheck.map (Predicate.of_iri)

let object' =
  QCheck.(
    [iri |> map( Object.of_iri);
     blank_node |> map (Object.of_blank_node);
     literal |> map (Object.of_literal);
    ]
    |> choose)

let triple =
  QCheck.triple
    subject
    predicate
    object'
  |> QCheck.map (fun(s,p,o) -> Triple.make s p o)

let rdf =
  QCheck.string
  |> QCheck.map(Namespace.rdf)

let rdfs =
  QCheck.string
  |> QCheck.map(Namespace.rdfs)
let owl =
  QCheck.string
  |> QCheck.map(Namespace.owl)

let xsd =
  QCheck.string
  |> QCheck.map(Namespace.xsd)