aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlleyCat <info@alleycat.cc>2021-06-07 14:54:31 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:02:45 +0200
commit618d4dc294d0613de8747a2b14aec89429958b8a (patch)
tree08c075809eb8b7690e1ef1b3392f3215284bd889
parent23adcf64b873ad6b0c97d288e4066786faf96c32 (diff)
Rdf turtle:
add object' tests and predobjs tests
-rw-r--r--lib/turtle/rdf_turtle.ml50
-rw-r--r--lib/turtle/rdf_turtle.mli2
-rw-r--r--test/turtle/main.ml50
3 files changed, 65 insertions, 37 deletions
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
index 4ddacc8..631446e 100644
--- a/lib/turtle/rdf_turtle.ml
+++ b/lib/turtle/rdf_turtle.ml
@@ -74,7 +74,7 @@ module AST = struct
(* TODO check whether this is nice *)
let pp ppf prefixed_name =
- Fmt.pf ppf "@[<8> 1><prefixed_name fst@ %s snd@ %s>@"
+ Fmt.pf ppf "@[<h 1><prefixed_name fst@ %s snd@ %s>@]"
(fst prefixed_name)
(snd prefixed_name)
@@ -159,6 +159,7 @@ module AST = struct
type t = Pred_iri of Iri.t | Pred_a
let of_iri iri = Pred_iri iri
+ let a = Pred_a
let equal a b =
match (a, b) with
@@ -326,7 +327,10 @@ module Parser = struct
(string "^^" *> iri))
let predicate =
- lift AST.Predicate.of_iri iri
+ choice [
+ lift (fun _ -> AST.Predicate.a) (char 'a' <* whitespace);
+ lift AST.Predicate.of_iri iri
+ ]
(* TODO if you change the order of literal and iri, the tests won't work anymore. *)
(* This is because the prefixed name parser accepts, for example: *)
@@ -335,24 +339,34 @@ module Parser = struct
let object_ collection bnodeps =
choice [
(lift
- (fun literal -> AST.Obj_literal literal)
- literal
+ (fun collection ->
+ Fmt.pr "collection@.";
+ AST.Obj_coll collection)
+ collection
);
(lift
- (fun blank_node -> AST.Obj_blank_node blank_node)
- blank_node
+ (fun bnodeps ->
+ Fmt.pr "bnodeps@.";
+ AST.Obj_BnodPs bnodeps)
+ bnodeps
);
(lift
- (fun iri -> AST.Obj_iri iri)
- iri);
- (lift
- (fun bnodeps -> AST.Obj_BnodPs bnodeps)
- bnodeps
+ (fun literal ->
+ Fmt.pr "literal@.";
+ AST.Obj_literal literal)
+ literal
);
(lift
- (fun collection -> AST.Obj_coll collection)
- collection
+ (fun blank_node ->
+ Fmt.pr "blank node@.";
+ AST.Obj_blank_node blank_node)
+ blank_node
);
+ (lift
+ (fun iri ->
+ Fmt.pr "iri: %a@." AST.Iri.pp iri;
+ AST.Obj_iri iri)
+ iri);
]
let collection_ bnodeps =
@@ -375,6 +389,10 @@ module Parser = struct
let collection = collection_ bnodeps in
choice [
(lift
+ (fun collection -> AST.Sub_coll collection)
+ collection
+ );
+ (lift
(fun iri -> AST.Sub_iri iri)
iri
);
@@ -382,10 +400,6 @@ module Parser = struct
(fun blank_node -> AST.Sub_blank_node blank_node)
blank_node
);
- (lift
- (fun collection -> AST.Sub_coll collection)
- collection
- )
]
let bnodeps_ predobjs =
@@ -414,7 +428,7 @@ module Parser = struct
let bnodeps = bnodeps_ predobjs in
let collection = collection_ bnodeps in
let object' = object_ collection bnodeps in
- sep_by semicolon (
+ sep_by1 semicolon (
lift2
(fun p objs -> (p, objs))
(whitespace *> predicate <* whitespace)
diff --git a/lib/turtle/rdf_turtle.mli b/lib/turtle/rdf_turtle.mli
index 2f5318d..c62b076 100644
--- a/lib/turtle/rdf_turtle.mli
+++ b/lib/turtle/rdf_turtle.mli
@@ -117,6 +117,8 @@ module AST : sig
val of_iri : Iri.t -> t
+ val a : t
+
val equal : t -> t -> bool
val pp : t Fmt.t
diff --git a/test/turtle/main.ml b/test/turtle/main.ml
index ea13811..6ada3e4 100644
--- a/test/turtle/main.ml
+++ b/test/turtle/main.ml
@@ -124,23 +124,23 @@ let predicate_test_case =
let object_test_case =
let cases = [
- (* Literal *)
+ (* Literal *)
"\"That Seventies Show\"^^xsd:string",
Turtle.Literal.make
("That Seventies Show")
(Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")
|> (fun lit -> Turtle.Obj_literal lit) ;
- (* Iri *)
+ (* Iri *)
"xsd:string",
Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"
|> (fun iri -> Turtle.Obj_iri iri) ;
- (* Blank_node *)
+ (* Blank_node *)
"_:string",
Turtle.Obj_blank_node (Turtle.Blank_node.of_string "string") ;
- (* Blank_node *)
+ (* Blank_node *)
"_:string",
Turtle.Obj_blank_node (Turtle.Blank_node.of_string "string") ;
- (* Collection *)
+ (* Collection *)
"( \"apple\" \"banana\" )",
Turtle.Obj_coll (
Turtle.Collection (
@@ -158,20 +158,13 @@ let object_test_case =
) ;
(* BNodePlist *)
"[ foaf:name \"Bob\" ]",
- Turtle.Obj_coll (
- Turtle.Collection (
- [
- Turtle.Obj_literal (
- Turtle.Literal.make
- ("apple")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")) ;
- Turtle.Obj_literal (
- Turtle.Literal.make
- ("banana")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")) ;
- ]
- )
- ) ;
+ Turtle.Obj_BnodPs (Turtle.BNodePs ([ Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "foaf" "name",
+ [ Turtle.Obj_literal ( Turtle.Literal.make
+ ("Bob")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"))
+ ]
+ ]))
+ ;
] in
test_case "object" `Quick
(fun () ->
@@ -214,6 +207,25 @@ let predobjs_test_case =
]
]
;
+ "rel:enemyOf <#green-goblin> ;
+ a foaf:Person ;
+ foaf:name \"Spiderman\", \"Человек-паук\"@ru",
+ [ Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "rel" "enemyOf",
+ [ Turtle.Obj_iri ( Turtle.Iri.of_iriref (Turtle.Iriref.of_string "#green-goblin"));]
+ ;
+ Turtle.Predicate.a,
+ [ Turtle.Obj_iri (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "foaf" "Person");]
+ ;
+ Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "foaf" "name",
+ [ Turtle.Obj_literal ( Turtle.Literal.make
+ ("Spiderman")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"));
+ Turtle.Obj_literal ( Turtle.Literal.make
+ ("Человек-паук")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")
+ ~language:"ru");
+ ]
+ ]
] in
test_case "predobjs" `Quick
(fun () ->