aboutsummaryrefslogtreecommitdiff
path: root/bin/main.ml
blob: 091a6d6d7c101740045d56ef6fc07919c139f7f9 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
module Parser = Rdf_turtle.Parser

module Ast = Rdf_turtle.Ast

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

let test (parser_str, parse_str, parser', pp) =
    let () = Fmt.pr "\n@.Trying string:@. %s@. with parser %s@." parse_str parser_str in
    parse_str |> parse parser' |> function
      | Ok x -> Fmt.pr "... ok ... pp_output is:@. %a @." pp x
      | Error e -> raise (Failure (Fmt.str "error: %s@." e))

let turtle_list =
  [
(*     SUBJECT = COLLECTION , this works! *)
    "() <http://a.example/p> <http://a.example/o> ."
    ;
    "('''hello''') <http://a.example/p> <http://a.example/o> ."
    ;
    "('1' '2') <http://a.example/p> <http://a.example/o> ."
    ;
    "('1' '2' '3') <http://a.example/p> <http://a.example/o> ."
    ;

(*     OBJECT = COLLECTION, this works! *)
    "<http://a.example/s>  <http://a.example/p> () ."
    ;
    "<http://a.example/s>  <http://a.example/p> ('1') ."
    ;
    "<http://a.example/s>  <http://a.example/p> ('1' '2') ."
    ;
    "<http://a.example/s>  <http://a.example/p> ('1' '2' '3') ."
    ;

(*     SUBJECT = BNODPS, this works *)
    "[] <http://a.example/p> <http://a.example/o> ."
    ;
    "
    @prefix as: <https://www.w3.org/ns/activitystreams#> .
    [ a as:Person ; ]
      <http://a.example/p> <http://a.example/o> ."
    ;
    "
    @prefix as: <https://www.w3.org/ns/activitystreams#> .
      @prefix ldp: <http://www.w3.org/ns/ldp#> .

    [ a as:Person ;
       ldp:inbox <http://localhost:4000/users/alice/inbox> ;
     ]
      <http://a.example/p> <http://a.example/o> ."
    ;

    (*   TRIPLE / SUBJECT / OBJECT = BNODPS, this works *)
    (* This is parsed, but no triple is emmited .. *)
    "[] ."
    ;
    "[<pred> <obj>] ."
    ;
    "[] <pred> <obj> ."
    ;
    "<sub> <pred> [] ."
    ;
    "<sub> <pred> [<pred2> <obj2>] ."
    ;
    "<sub> <pred> [<pred2> <obj2>, <obj3> ; <pred4> <obj4>, <obj5>] ."
    ;

(*     NESTED BNODPS (in subject), this works *)
    "[ <http://a.example/p1> [ <http://a.example/p2> <http://a.example/o2> ] ; <http://a.example/p> <http://a.example/o> ]."
    ;

(*     BNODPS (as triple) CONTAINING COLLECTION, this works *)
    "[ <http://a.example/p1> ('1') ] ."
    ;

(*     NESTED COLLECTIONS, this works *)
    "<http://a.example/s> <http://a.example/p> (('1')) ."
    ;
    "<http://a.example/s> <http://a.example/p> ('1' ('2')) ."
    ;

(*     A MORE REALISTIC EXAMPLE *)
    "@prefix as: <https://www.w3.org/ns/activitystreams#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://localhost:4000/users/alice>
    a as:Person ;
    ldp:inbox <http://localhost:4000/users/alice/inbox> ;
    as:outbox <http://localhost:4000/users/alice/outbox> ;
    as:preferredUsername \"alice\" .
    "
    ;
  ]

(* let test_ctx : Rdf_turtle.Ast.state = *)
(*   { *)
(*     base_uri = "base" |> Iri.of_string; *)
(*     namespaces = Rdf_turtle.Ast.SMap.empty; *)
(*     bnode_counter = 0; *)
(*   } *)
(*  *)
(* let empty_graph = Graph.empty *)

let () =
  List.iter (
    fun turtle_str ->
      turtle_str
      |> (fun turtle ->
          Fmt.pr "@.THE TURTLE STRING: %s@." turtle;
          turtle)
      |> Rdf_turtle.decode
      |> Rdf.Graph.to_triples
      |> Seq.iter (fun triple ->
          Fmt.pr "@.%a" Rdf.Triple.pp triple;
        )
  ) turtle_list

(*   List.iter ( *)
(*     fun statement_str -> *)
(*       statement_str *)
(*       |> (fun str -> *)
(*           Fmt.pr "The statement_str: %s@." str; *)
(*           str) *)
(*       |> parse Parser.statement *)
(*       |> (function *)
(*           | Ok x -> Fmt.pr "... ok ... pp_output is:@. %a @." Ast.Statement.pp x; x *)
(*           | Error e -> raise (Failure (Fmt.str "error: %s@." e))) *)
(*       |> (fun statement -> *)
(*           Rdf_turtle.apply_statement (test_ctx, empty_graph) statement) *)
(*       |> (fun (_ctx, g) -> *)
(*           List.of_seq @@ Graph.to_triples @@ g) *)
(*       |> List.iter (fun triple -> *)
(*           Fmt.pr "%a@." Triple.pp triple) *)
(*   ) turtle_list ; *)

>>>>>>> a64d084 (Cleaned up some code, changed a few names. Added a test function in)
(*   test ("literal", "\"Cette Série des Années Septantei\"^^<iri>@lang", Parser.literal, Ast.Literal.pp) ; *)
(*  *)
(*   test ("iriref", "<http://example.org/#spidermanhhhhhhhhhhhhhh>", Parser.iriref, Ast.Iriref.pp) ; *)
(*   test ("language", "@en-fr", Parser.language, Ast.Language.pp) ; *)
(*   test ("iri", "a:p", Parser.iri, Ast.Iri.pp) ; *)
(*   test ("prefixed_name", "rdfs:some-example", Parser.prefixed_name, Ast.Prefixed_name.pp) ; *)
(*   test ("blank_node", "_:some-example", Parser.blank_node, Ast.Blank_node.pp) ; *)
(*   test ("iri" , "<https://someiri.com/blah>", Parser.iri, Ast.Iri.pp) ; *)
(*   test ("iri" , "rdfsk:irir", Parser.iri, Ast.Iri.pp) ; *)
(*   test ("literal", "\"hia\"", Parser.literal, Ast.Literal.pp) ; *)
(*   test ("literal", "\"Cette Série des Années Septantei\"@be", Parser.literal, Ast.Literal.pp) ; *)
(*   test ("literal", "\"Cette Série des Années Septantei\"^^xsd:string", Parser.literal, Ast.Literal.pp) ; *)
(*   test ("predicate", "b:a", Parser.predicate, Ast.Predicate.pp) ; *)
(*   test ("object (iri)", "a:p", Parser.object', Ast.object_pp) ; *)
(*   test ("object (bnode)", "_:blabla", Parser.object', Ast.object_pp) ; *)
(*   test ("object (literal)", "\"Cette Série des Années Septantei\"^^<iri>", Parser.object', Ast.object_pp) ; *)
(*   test ("object (coll)", "(_:a _:b <iriobj> rdfs:o)", Parser.object', Ast.object_pp) ; *)
(*   test ("object (bnodps)", "[ <predicate> <object> ]", Parser.object', Ast.object_pp) ; *)
(*   test ("object (bnodps)", "[ <pred1> <obj1>; <pred2> <obj2>, <obj3> ]", Parser.object', Ast.object_pp) ; *)
(*   test ("object (bnodps)", "[ a:p a:o1 ]", Parser.object', Ast.object_pp) ; *)
(*   test ("object (bnodps)", *)
(*         "[ rel:enemyOf <#green-goblin>, \"henkie\"; *)
(*            rel:enemyOf <#green-goblin>, _:sjaak; *)
(*            a foaf:Person ; *)
(*            foaf:name \"Spiderman\", \"Человек-паук\"@ru]", *)
(*         Parser.object', Ast.object_pp) ; *)
(*   test ("subject (iri)", "alaaf:potverdorie", Parser.subject, Ast.subject_pp) ; *)
(*   test ("subject (iri)", "<#spiderman>", Parser.subject, Ast.subject_pp) ; *)
(*   test ("subject (blank_node)", "_:potverdorie", Parser.subject, Ast.subject_pp) ; *)
(*   test ("subject (bnodps)", *)
(*         "[ rel:enemyOf <#green-goblin>, \"henkie\"; *)
(*            rel:enemyOf <#green-goblin>, _:sjaak; *)
(*            a foaf:Person ; *)
(*            foaf:name \"Spiderman\", \"Человек-паук\"@ru]", *)
(*         Parser.subject, Ast.subject_pp) ; *)
(*   test ("subject (collection)", "( _:a _:b _:c)", Parser.subject, Ast.subject_pp) ; *)
(*   test ("bnodps", "[ p:a _:b, _:c   ]", Parser.bnodps, Ast.bnodps_pp) ; *)
(*   test ("predobjs", " p:a _:b, _:c   ", Parser.predobjs, Ast.predobjs_pp) ; *)
(*   test ("predobjs", *)
(*         " rel:enemyOf <#green-goblin> ; *)
(*                     a foaf:Person ; *)
(*                     foaf:name \"Spiderman\", \"Человек-паук\"@ru ", *)
(*         Parser.predobjs, Ast.predobjs_pp) ; *)
(*   test ("triples", "[ p:a _:b, _:c  ] ", Parser.triples, Ast.Triple.pp) ; *)
(*   test ("triples", "<#spiderman> <what> <#green-goblin> ", Parser.triples, Ast.Triple.pp) ; *)
(*   test ("triples", *)
(*         "    <#spiderman> rel:enemyOf <#green-goblin> ; *)
(*                     a foaf:Person ; *)
(*                     foaf:name \"Spiderman\", \"Человек-паук\"@ru", *)
(*                     Parser.triples, Ast.Triple.pp) ; *)
(*   test ("directive", "@base <http://one.example/>", Parser.directive, Ast.Directive.pp) ; *)
(*   test ("directive", "@prefix foaf: <http://xmlns.com/foaf/0.1/>", Parser.directive, Ast.Directive.pp) ; *)
(*   test ("statement", "@base <http://one.example/> . ", Parser.statement, Ast.Statement.pp) ; *)
(*   test ("statement", *)
(*         "    <#spiderman> rel:enemyOf <#green-goblin> ; *)
(*                     a foaf:Person ; *)
(*                     foaf:name \"Spiderman\", \"Человек-паук\"@ru . ", *)
(*         Parser.statement, Ast.Statement.pp) ; *)
(*   test ("turtle", *)
(*    "     @base <http://example.org/> . *)
(* @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . *)
(* @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . *)
(* @prefix foaf: <http://xmlns.com/foaf/0.1/> . *)
(*  *)
(* <#green-goblin> *)
(*     rel:enemyOf <#spiderman> ; #LET us put a comment here *)
(*     a foaf:Person ; *)
(*     foaf:name \"Green Goblin\" . *)
(*  *)
(* @prefix rel: <http://www.perceive.net/schemas/relationship/> . *)
(* <#spiderman> *)
(*     rel:enemyOf <#green-goblin> ; *)
(*     a foaf:Person ; *)
(*     foaf:name \"Spiderman\", \"Человек-паук\"@ru . ", *)
(*         Parser.turtle, Ast.Turtle.pp) ; *)