aboutsummaryrefslogtreecommitdiff
path: root/bin/main.ml
blob: d1001ba953c6f0275e92ff05facf4ee85b05ff85 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
module Parser = Rdf_turtle.Parser

open Rdf

let parse p =
  Angstrom.parse_string
    ~consume:Angstrom.Consume.All
    p

let turtle_list =
  [
(*     "<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> _:a ." *)
(*     ; *)
(*     "(_:a _:b) *)
(*     <http://www.perceive.net/schemas/relationship/enemyOf> _:a ." *)
(*     ; *)
(*     "(<A-iri> <B-iri>) <http://www.perceive.net/schemas/relationship/enemyOf> _:a ." *)
(*     "(<A-iri>) <http://www.perceive.net/schemas/relationship/enemyOf> _:a ." *)
(*     ; *)
  ]

let test_sub =
  "test_sub"
  |> Rdf.Iri.of_string
  |> Rdf.Triple.Subject.of_iri

let test_pred =
  "test_sub"
  |> Rdf.Iri.of_string
  |> Rdf.Triple.Predicate.of_iri

let test_iri =
  "hey-some-iri!"
  |> Rdf.Iri.of_string

let test_iri_2 =
  "http://example.org/#spiderman"
  |> Rdf.Iri.of_string

let test_ctx : Rdf_turtle.Ast.parser_state =
  {
    base_uri = "base" |> Iri.of_string;
    namespaces = Rdf_turtle.Ast.SMap.empty;
    bnode_labels = Rdf_turtle.Ast.SMap.empty;
    cur_subject = test_sub;
    cur_predicate = test_pred;
  }

let empty_graph = Graph.empty

let str_iriref = "<http://example.org/#spidermanhhhhhhhhhhhhhh>"
let ast_iriref =
  str_iriref
  |> parse Parser.iriref
  |> Result.get_ok

let str_language = "@en-fr"
let ast_language =
  str_language
  |> parse Parser.language
  |> Result.get_ok

let str_prefixed_name = "rdfs:some-example"
let ast_prefixed_name =
  str_prefixed_name
  |> parse Parser.prefixed_name
  |> Result.get_ok

let str_blank_node = "_:some-example"
let ast_blank_node =
  str_blank_node
  |> parse Parser.blank_node
  |> Result.get_ok

let str_iri1 = "<https://some_iri.com/blah>"
let ast_iri1 =
  str_iri1
  |> parse Parser.iri
  |> Result.get_ok

let str_iri2 = "rdfks:irir"
let ast_iri2 =
  str_iri2
  |> parse Parser.iri
  |> Result.get_ok

let str_literal0 = "\"hia\""
let ast_literal0 =
  str_literal0
  |> parse Parser.literal
  |> Result.get_ok

let str_literal1 = "\"Cette Série des Années Septantei\"@be"
let ast_literal1 =
  str_literal1
  |> parse Parser.literal
  |> Result.get_ok

let str_literal2 = "\"Cette Série des Années Septantei\"^^<iri>"
let ast_literal2 =
  str_literal2
  |> parse Parser.literal
  |> Result.get_ok

let str_literal3 = "\"Cette Série des Années Septantei\"^^<iri>@lang"
(* let ast_literal3 = *)
(*   str_literal3 *)
(*   |> parse Parser.literal *)
(*   |> Result.get_ok *)

let str_predicate = "<iril]lfdsjk%>"
let ast_predicate =
  str_predicate
  |> parse Parser.predicate
  |> Result.get_ok

let str_object_iri = "<iril]lfdsjk%>"
let ast_object_iri =
  str_object_iri
  |> parse Parser.object'
  |> Result.get_ok

let str_object_bnode = "_:blabal"
let ast_object_bnode =
  str_object_bnode
  |> parse Parser.object'
  |> Result.get_ok

(* let str_object_literal = "\"Cette Série des Années Septantei\"^^<iri>" *)
let str_object_literal = ":a"
let ast_object_literal =
  str_object_literal
  |> parse Parser.object'
  |> Result.get_ok

let str_object_coll = "(   _:a _:b <iriobj> rdfs:o   )"
let ast_object_coll =
  str_object_coll
  |> parse Parser.object'
  |> Result.get_ok

let str_object_bnodps = "[ _:p _:o1 ]"
(*     "[ foaf:name \"Bob\" ]", *)
let ast_object_bnodps =
  str_object_bnodps
  |> parse Parser.object'
  |> Result.get_ok

let () =
  List.iter (
    fun statement_str ->
      statement_str
      |> parse Parser.statement
      |> Result.get_ok
      |> (fun statement ->
          Fmt.pr "%a@." Rdf_turtle.Ast.Statement.pp statement;
          statement
        )
      |> (fun statement ->
          Rdf_turtle.apply_statement (test_ctx, empty_graph) statement)
      |> (fun (_ctx, g) ->
          Graph.to_list @@ g)
      |> List.iter (fun triple ->
          Fmt.pr "%a@." Triple.pp triple)
  ) turtle_list ;
  Fmt.pr "IRI: %a @." Iri.pp test_iri;
  Fmt.pr "IRI_2: %a @." Iri.pp test_iri_2;
  Fmt.pr "@. Now we get some pring statements@.";
  Fmt.pr "LANGUAGE: %a @." Rdf_turtle.Ast.Language.pp ast_language;
  Fmt.pr "IRIREF: %a @." Rdf_turtle.Ast.Iriref.pp ast_iriref;
  Fmt.pr "PREFIXED_NAME: %a @." Rdf_turtle.Ast.Prefixed_name.pp ast_prefixed_name;
  Fmt.pr "BLANK_NODE: %a @." Rdf_turtle.Ast.Blank_node.pp ast_blank_node;
  Fmt.pr "IRI1: %a @." Rdf_turtle.Ast.Iri.pp ast_iri1;
  Fmt.pr "IRI2: %a @." Rdf_turtle.Ast.Iri.pp ast_iri2;
  Fmt.pr "LITERAL0: %a @." Rdf_turtle.Ast.Literal.pp ast_literal0;
  Fmt.pr "LITERAL1: %a @." Rdf_turtle.Ast.Literal.pp ast_literal1;
  Fmt.pr "LITERAL2: %a @." Rdf_turtle.Ast.Literal.pp ast_literal2;
(*   Fmt.pr "LITERAL3: %a @." Rdf_turtle.Ast.Literal.pp ast_literal3; *)
  Fmt.pr "PREDICATE: %a @." Rdf_turtle.Ast.Predicate.pp ast_predicate;
  Fmt.pr "OBJECT_IRI: %a @." Rdf_turtle.Ast.object_pp ast_object_iri;
  Fmt.pr "OBJECT_BNODE: %a @." Rdf_turtle.Ast.object_pp ast_object_bnode;
  Fmt.pr "OBJECT_LITERAL: %a @." Rdf_turtle.Ast.object_pp ast_object_literal;
  Fmt.pr "OBJECT_COLL: %a @." Rdf_turtle.Ast.object_pp ast_object_coll;
  Fmt.pr "OBJECT_BNODPS: %a @." Rdf_turtle.Ast.object_pp ast_object_bnodps;