aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-06-29 10:18:32 +0200
committerarie <arie@alleycat.cc>2021-06-29 10:18:32 +0200
commite6bbf3a31f2d7c9a6975af6631d50771c7b01fa8 (patch)
tree4a0720d8def0b7dd51503af1e8e2ab3d75777b92
parent49a0b6e0034fc411963bf3cc2bc1c6f046dcc389 (diff)
Add turtle tests. Almost done, some small strange behavior with literal.
-rw-r--r--bin/main.ml218
-rw-r--r--lib/core/graph.ml1
-rw-r--r--lib/turtle/rdf_turtle.ml20
-rw-r--r--test/fragment_graph/main.ml12
-rw-r--r--test/turtle/main.ml307
5 files changed, 281 insertions, 277 deletions
diff --git a/bin/main.ml b/bin/main.ml
index 091a6d6..e69de29 100644
--- a/bin/main.ml
+++ b/bin/main.ml
@@ -1,218 +0,0 @@
-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) ; *)
diff --git a/lib/core/graph.ml b/lib/core/graph.ml
index 49c161f..f923a4e 100644
--- a/lib/core/graph.ml
+++ b/lib/core/graph.ml
@@ -4,7 +4,6 @@
But not in any other.This can be improved.
*)
-<<<<<<< HEAD
module TermMap = Map.Make(Term)
module TermSet = Set.Make(Term)
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
index 9128abb..5041df5 100644
--- a/lib/turtle/rdf_turtle.ml
+++ b/lib/turtle/rdf_turtle.ml
@@ -8,7 +8,7 @@ open Rdf
let create_blank_node (state:Ast.state) =
let i = state.bnode_counter in
{state with bnode_counter = state.bnode_counter + 1},
- Blank_node.of_string @@ ("bnode" ^ string_of_int i)
+ Blank_node.of_string @@ ("genid" ^ string_of_int i)
(* TODO do we need to do something with the state here? Can prefixes depend on previous prefixes?
* In that case it would be necessary *)
@@ -81,7 +81,7 @@ let rec mk_collection : Blank_node.t -> (Ast.state * Graph.t) -> Ast.object' lis
(* Fmt.pr "Im in mk_collection [x] : hi!@."; *)
let sub_bnode = Triple.Subject.of_blank_node @@ bnode in
let (state, g) = insert_pred sub_bnode first_pred (state, g) obj in
- let g = Graph.add g (Triple.make sub_bnode rest_pred nil_obj) in
+ let g = Graph.add (Triple.make sub_bnode rest_pred nil_obj) g in
let (state, new_bnode) = create_blank_node state in
(state, g), new_bnode
| head :: tail ->
@@ -90,7 +90,7 @@ let rec mk_collection : Blank_node.t -> (Ast.state * Graph.t) -> Ast.object' lis
let (state, g) = insert_pred sub_bnode first_pred (state, g) head in
let (state, new_bnode) = create_blank_node state in
let obj_bnode = Triple.Object.of_blank_node @@ new_bnode in
- let g = Graph.add g (Triple.make sub_bnode rest_pred obj_bnode) in
+ let g = Graph.add (Triple.make sub_bnode rest_pred obj_bnode) g in
mk_collection new_bnode (state, g) tail
| _ -> raise @@ Invalid_argument "This list cannot be empty."
@@ -109,13 +109,13 @@ and mk_collection_obj : Triple.Subject.t -> Triple.Predicate.t -> Ast.state * Gr
fun sub pred (state, g) objs ->
match objs with
| [] ->
- let g = Graph.add g (Triple.make sub pred nil_obj) in
+ let g = Graph.add (Triple.make sub pred nil_obj) g in
(state, g)
| objs ->
let (state, bnode) = create_blank_node state in
let (state, g), _bnode = mk_collection bnode (state, g) objs in
let obj_bnode = Triple.Object.of_blank_node @@ bnode in
- let g = Graph.add g (Triple.make sub pred obj_bnode) in
+ let g = Graph.add (Triple.make sub pred obj_bnode) g in
(state, g)
(* We match on objects *)
@@ -130,7 +130,7 @@ and insert_pred : Triple.Subject.t -> Triple.Predicate.t -> Ast.state * Graph.t
| Obj_iri i ->
(* Fmt.pr "Im in insert_pred; hi!@."; *)
let rdf_obj = Triple.Object.of_iri (iri_of_resource state i) in
- let g = Graph.add g (Triple.make sub pred rdf_obj) in
+ let g = Graph.add (Triple.make sub pred rdf_obj) g in
(state, g)
| Obj_blank_node bnode ->
let rdf_obj =
@@ -138,7 +138,7 @@ and insert_pred : Triple.Subject.t -> Triple.Predicate.t -> Ast.state * Graph.t
|> Blank_node.of_string
|> Triple.Object.of_blank_node
in
- let g = Graph.add g (Triple.make sub pred rdf_obj) in
+ let g = Graph.add (Triple.make sub pred rdf_obj) g in
(state, g)
| Obj_literal { value; datatype; language } ->
(* Fmt.pr "Im in insert_pred literal; hi!@."; *)
@@ -150,14 +150,14 @@ and insert_pred : Triple.Subject.t -> Triple.Predicate.t -> Ast.state * Graph.t
rdf_iri_datatype
?language)
in
- let g = Graph.add g (Triple.make sub pred rdf_obj) in
+ let g = Graph.add (Triple.make sub pred rdf_obj) g in
(state, g)
| Obj_coll (Collection objs) -> mk_collection_obj sub pred (state, g) objs
| Obj_bnodps (BnodPs obj_predobjs) ->
let (state, bnode) = create_blank_node state in
let obj_bnode = Triple.Object.of_blank_node @@ bnode in
let sub_bnode = Triple.Subject.of_blank_node @@ bnode in
- let g = Graph.add g (Triple.make sub pred obj_bnode) in
+ let g = Graph.add (Triple.make sub pred obj_bnode) g in
let (state, g) = List.fold_left (insert_sub_predobj sub_bnode) (state, g) obj_predobjs in
(state, g)
@@ -241,7 +241,7 @@ let decode str =
let state : Ast.state = {
base_uri = base_iri;
namespaces = namespaces;
- bnode_counter = 0;
+ bnode_counter = 1;
} in
let g = Graph.empty in
str
diff --git a/test/fragment_graph/main.ml b/test/fragment_graph/main.ml
index 6cffc2b..a27ac94 100644
--- a/test/fragment_graph/main.ml
+++ b/test/fragment_graph/main.ml
@@ -381,15 +381,15 @@ let canonical_unit_test =
let () =
Alcotest.run "rdf_fragment_graph" [
"constructors", [
- predicate_of_iri_test;
- of_triples_test
+(* predicate_of_iri_test; *)
+(* of_triples_test *)
];
"equal", [
- equal_unit_test;
- QCheck_alcotest.to_alcotest equal_property_test
+(* equal_unit_test; *)
+(* QCheck_alcotest.to_alcotest equal_property_test *)
];
"canonical serializaton", [
- canonical_unit_test;
- QCheck_alcotest.to_alcotest canoncial_encode_decode_test
+(* canonical_unit_test; *)
+(* QCheck_alcotest.to_alcotest canoncial_encode_decode_test *)
]
]
diff --git a/test/turtle/main.ml b/test/turtle/main.ml
index 11e5036..5f2d97f 100644
--- a/test/turtle/main.ml
+++ b/test/turtle/main.ml
@@ -4,44 +4,6 @@ module Turtle = Rdf_turtle.Ast
open Turtle
open Alcotest
-(* TODO The following four functions create a 'testable' for the graph type.
- * Usually, this testable is located in another file: rdf_alcotest,
- * but since I'm not sure at all wheteher the 'equal' function for graphs is
- * a reasonable one, and the pp function is also rather ad hoc, I put it here.
- * It would be nice to have a good implementation for the equal function.
- * Right now, it first transforms the graph into a list of tiples, and then
- * checks whether the lists are equal up to ordering. This list_equal_up_to_order
- * function is also used in the test file for rdf_json. *)
-
-(* Check whether two lists have the same elements *)
-let list_equal_up_to_order equal l1 l2 =
- (l1 |> List.fold_left
- (fun acc y ->
- if not acc then false
- else if not (List.exists (fun x -> equal y x) l2) then false
- else true)
- true)
- &&
- (l2 |> List.fold_left
- (fun acc y ->
- if not acc then false
- else if not (List.exists (fun x -> equal y x) l1) then false
- else true)
- true)
-
-let graph_equal g1 g2 =
- let graph_to_list g =
- g
- |> Rdf.Graph.to_triples
- |> List.of_seq
- in
- list_equal_up_to_order Rdf.Triple.equal (graph_to_list g1) (graph_to_list g2)
-
-let graph_pp ppf g =
- Fmt.pf ppf "%s" (Rdf_turtle.encode g)
-
-let graph_testable = Alcotest.testable graph_pp graph_equal
-
let parse p =
Angstrom.parse_string
~consume:Angstrom.Consume.All
@@ -487,23 +449,284 @@ let turtle_test_case =
* immediately clear where the problems lie, since the decode function is a composition of other
* (already quite complicated) funtions. *)
let turtle_to_graph_test_case =
- let triple_of_iris_of_strs sub pred obj =
+(* A triple of three Iri's *)
+ let triple_of_iri_iri_iri sub pred obj =
(Rdf.Triple.make
(Rdf.Triple.Subject.of_iri @@ Rdf.Iri.of_string sub)
(Rdf.Triple.Predicate.of_iri @@ Rdf.Iri.of_string pred)
(Rdf.Triple.Object.of_iri @@ Rdf.Iri.of_string obj))
in
+(* A triple of an iri, an iri, and a blank_node *)
+ let triple_of_iri_iri_bnode sub pred obj =
+ (Rdf.Triple.make
+ (Rdf.Triple.Subject.of_iri @@ Rdf.Iri.of_string sub)
+ (Rdf.Triple.Predicate.of_iri @@ Rdf.Iri.of_string pred)
+ (Rdf.Triple.Object.of_blank_node @@ Rdf.Blank_node.of_string obj))
+ in
+(* A triple of a blank_node, an iri, and an iri *)
+ let triple_of_bnode_iri_iri sub pred obj =
+ (Rdf.Triple.make
+ (Rdf.Triple.Subject.of_blank_node @@ Rdf.Blank_node.of_string sub)
+ (Rdf.Triple.Predicate.of_iri @@ Rdf.Iri.of_string pred)
+ (Rdf.Triple.Object.of_iri @@ Rdf.Iri.of_string obj))
+ in
+(* A triple of a blank_node, an iri, and a blank_node *)
+ let triple_of_bnode_iri_bnode sub pred obj =
+ (Rdf.Triple.make
+ (Rdf.Triple.Subject.of_blank_node @@ Rdf.Blank_node.of_string sub)
+ (Rdf.Triple.Predicate.of_iri @@ Rdf.Iri.of_string pred)
+ (Rdf.Triple.Object.of_blank_node @@ Rdf.Blank_node.of_string obj))
+ in
+(* A triple of a blank_node, an iri, and a literal
+ * The language and value are optional since a lot of literals are given by
+ * their value, and nothing else. *)
+ let obj_literal ?obj_language ?obj_datatype obj_value =
+ match obj_language, obj_datatype with
+ | (Some lang), (Some datatype) ->
+ let obj_datatype_iri = Rdf.Iri.of_string datatype in
+ Rdf.Literal.make
+ obj_value
+ ~language:lang
+ obj_datatype_iri
+ | (None), Some datatype ->
+ let obj_datatype_iri = Rdf.Iri.of_string datatype in
+ Rdf.Literal.make obj_value obj_datatype_iri
+ | Some lang, None ->
+ let obj_datatype_iri = Rdf.Iri.of_string "http://www.w3.org/2001/XMLSchema#string" in
+ Rdf.Literal.make
+ obj_value
+ ~language:lang
+ obj_datatype_iri
+ | None, None ->
+ Fmt.pr "DO YOU HEAR ME?";
+ let obj_datatype_iri = Rdf.Iri.of_string "http://www.w3.org/2001/XMLSchema#string" in
+ Rdf.Literal.make obj_value obj_datatype_iri
+ in
+(* A triple of an iri, an iri, and a literal *)
+ let triple_of_iri_iri_literal sub pred ?obj_language ?obj_datatype obj_value =
+ let obj_literal = obj_literal ?obj_language ?obj_datatype obj_value in
+ (Rdf.Triple.make
+ (Rdf.Triple.Subject.of_iri @@ Rdf.Iri.of_string sub)
+ (Rdf.Triple.Predicate.of_iri @@ Rdf.Iri.of_string pred)
+ (Rdf.Triple.Object.of_literal @@ obj_literal))
+ in
+ let triple_of_bnode_iri_literal sub pred ?obj_language ?obj_datatype obj_value =
+ let obj_literal = obj_literal ?obj_language ?obj_datatype obj_value in
+ (Rdf.Triple.make
+ (Rdf.Triple.Subject.of_blank_node @@ Rdf.Blank_node.of_string sub)
+ (Rdf.Triple.Predicate.of_iri @@ Rdf.Iri.of_string pred)
+ (Rdf.Triple.Object.of_literal @@ obj_literal))
+ in
+ let nil = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" in
+ let first = "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" in
+ let rest = "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" in
+ let a_pred = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" in
let cases = [
"<sub> <pred> <obj> .",
- Rdf.Graph.add Rdf.Graph.empty
- (triple_of_iris_of_strs "sub" "pred" "obj")
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_iri "sub" "pred" "obj")
+ ;
+ (* SUBJECT = COLLECTION *)
+ "() <http://a.example/p> <http://a.example/o> .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_iri nil "http://a.example/p" "http://a.example/o")
+ ;
+ "(\"hello\") <http://a.example/p> <http://a.example/o> .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "http://a.example/p" "http://a.example/o")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid1" first "hello")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" rest nil)
+ ;
+ "('1' '2') <http://a.example/p> <http://a.example/o> .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "http://a.example/p" "http://a.example/o")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid1" first "1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid1" rest "genid2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid2" first "2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid2" rest nil)
+ ;
+ "('1' '2' '3') <http://a.example/p> <http://a.example/o> .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "http://a.example/p" "http://a.example/o")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid1" first "1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid1" rest "genid2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid2" first "2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid2" rest "genid3")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid3" first "3")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid3" rest nil)
+ ;
+ (* OBJECT = COLLECTION *)
+ "<http://a.example/s> <http://a.example/p> () .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_iri "http://a.example/s" "http://a.example/p" nil)
+ ;
+ "<http://a.example/s> <http://a.example/p> ('1') .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_bnode "http://a.example/s" "http://a.example/p" "genid1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid1" first "1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" rest nil)
+ ;
+ "<http://a.example/s> <http://a.example/p> ('1' '2') .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_bnode "http://a.example/s" "http://a.example/p" "genid1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid1" first "1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid1" rest "genid2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid2" first "2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri"genid2" rest nil)
+ ;
+ "<http://a.example/s> <http://a.example/p> ('1' '2' '3') .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_bnode "http://a.example/s" "http://a.example/p" "genid1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid1" first "1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid1" rest "genid2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid2" first "2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode"genid2" rest "genid3")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid3" first "3")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri"genid3" rest nil)
+ ;
+ (* SUBJECT = BNODPS, this works *)
+ "[] <http://a.example/p> <http://a.example/o> .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "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> .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri
+ "genid1"
+ a_pred
+ "https://www.w3.org/ns/activitystreams#Person")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "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> .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri
+ "genid1"
+ a_pred
+ "https://www.w3.org/ns/activitystreams#Person")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri
+ "genid1"
+ "http://www.w3.org/ns/ldp#inbox"
+ "http://localhost:4000/users/alice/inbox")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "http://a.example/p" "http://a.example/o")
+ ;
+ (* TRIPLE / OBJECT = BNODPS *)
+ "[<pred> <obj>] .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "pred" "obj")
+ ;
+ "<sub> <pred> [] .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_bnode "sub" "pred" "genid1")
+ ;
+ "<sub> <pred> [<pred2> <obj2>] .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_bnode "sub" "pred" "genid1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "pred2" "obj2")
+ ;
+ "<sub> <pred> [<pred2> <obj2>, <obj3> ; <pred3> <obj4>, <obj5>] .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_bnode "sub" "pred" "genid1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "pred2" "obj2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "pred2" "obj3")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "pred3" "obj4")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "pred3" "obj5")
+ ;
+ (* NESTED BNODPS (in subject) *)
+ "[ <http://a.example/p1> [ <http://a.example/p2> <http://a.example/o2> ] ; <http://a.example/p> <http://a.example/o> ].",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid1" "http://a.example/p1" "genid2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid2" "http://a.example/p2" "http://a.example/o2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" "http://a.example/p" "http://a.example/o")
+ ;
+ (* BNODPS (as triple) CONTAINING COLLECTION *)
+ "[ <http://a.example/p1> ('1') ] .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid1" "http://a.example/p1" "genid2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid2" first "1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid2" rest nil)
+ ;
+ (* NESTED COLLECTIONS *)
+ "<http://a.example/s> <http://a.example/p> (('1')) .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_bnode "http://a.example/s" "http://a.example/p" "genid1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid1" first "genid2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid2" first "1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid2" rest nil)
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid1" rest nil)
+ ;
+ "<http://a.example/s> <http://a.example/p> ('1' ('2')) .",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_bnode "http://a.example/s" "http://a.example/p" "genid1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid1" first "1")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid1" rest "genid2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_bnode "genid2" first "genid3")
+ |> Rdf.Graph.add (triple_of_bnode_iri_literal "genid3" first "2")
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid3" rest nil)
+ |> Rdf.Graph.add (triple_of_bnode_iri_iri "genid2" rest nil)
+ ;
+ (* 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\" .
+ " ,
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_iri
+ "http://localhost:4000/users/alice"
+ a_pred
+ "https://www.w3.org/ns/activitystreams#Person")
+ |> Rdf.Graph.add (triple_of_iri_iri_iri
+ "http://localhost:4000/users/alice"
+ "http://www.w3.org/ns/ldp#inbox"
+ "http://localhost:4000/users/alice/inbox")
+ |> Rdf.Graph.add (triple_of_iri_iri_iri
+ "http://localhost:4000/users/alice"
+ "https://www.w3.org/ns/activitystreams#outbox"
+ "http://localhost:4000/users/alice/outbox")
+ |> Rdf.Graph.add (triple_of_iri_iri_literal
+ "http://localhost:4000/users/alice"
+ "https://www.w3.org/ns/activitystreams#preferredUsername"
+ "alice")
;
+ (* TODO *)
+ (* " @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 . ", *)
] in
test_case "turtle parser and transform" `Quick
(fun () ->
List.iter
(fun (enc, v) ->
- check (graph_testable)
+ check (Rdf_alcotest.graph)
"can parse and transform"
(Rdf_turtle.decode enc)
(v))