aboutsummaryrefslogtreecommitdiff
path: root/bin/main.ml
blob: b7c62608a860c652470156f4b5140a9a1efa1be2 (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
module Parser = Rdf_turtle.Parser

open Rdf
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 =
  [
(*     "<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 () =
  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 ;
(*   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> ;
           a foaf:Person ;
           foaf:name \"Spiderman\", \"Человек-паук\"@ru]",
        Parser.object', Ast.object_pp) ;