aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-06-29 11:01:39 +0200
committerarie <arie@alleycat.cc>2021-06-29 11:01:39 +0200
commitbf545602512662d2f7735992a81ead9352d426c0 (patch)
tree75299a873ae579e54fdca9ac3181ebcf3fede6f5
parente6bbf3a31f2d7c9a6975af6631d50771c7b01fa8 (diff)
Rdf turtle tests.
Fix a little bug in the xsd:string uri in rdf_turtle. There was a < which shouldn't have been there. All the tests work now, except for the last one. I think the reason is that @base uri's are not taken into account yet.
-rw-r--r--lib/turtle/rdf_turtle.ml7
-rw-r--r--test/turtle/main.ml67
2 files changed, 53 insertions, 21 deletions
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
index 5041df5..cb3e3e8 100644
--- a/lib/turtle/rdf_turtle.ml
+++ b/lib/turtle/rdf_turtle.ml
@@ -29,10 +29,10 @@ let iri_of_iriref : Ast.Iriref.t -> Iri.t =
* string's themselves. *)
let iri_of_resource : Ast.state -> Ast.Iri.t -> Iri.t = fun
state ast_iri ->
-(* Fmt.pr "Im in iri_of_resource; hi!@."; *)
match ast_iri with
| Iriref str ->
- str |> Iri.of_string
+ str |>
+ Iri.of_string
| Prefixed_name (a, b) ->
let iri = Ast.SMap.find a state.namespaces in
let lst = b |> Ast.Iriref.to_string in
@@ -141,7 +141,6 @@ and insert_pred : Triple.Subject.t -> Triple.Predicate.t -> Ast.state * Graph.t
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!@."; *)
let rdf_iri_datatype = iri_of_resource state datatype in
let rdf_obj =
Triple.Object.of_literal
@@ -235,7 +234,7 @@ let parse p =
let decode str =
(* This 'string -> iri' map is needed because of the default datatype 'xsd:string' in literals *)
let xsd_iri =
- "<http://www.w3.org/2001/XMLSchema#"
+ "http://www.w3.org/2001/XMLSchema#"
|> Rdf.Iri.of_string in
let namespaces = Ast.SMap.add "xsd" xsd_iri Ast.SMap.empty in
let state : Ast.state = {
diff --git a/test/turtle/main.ml b/test/turtle/main.ml
index 5f2d97f..411e7a9 100644
--- a/test/turtle/main.ml
+++ b/test/turtle/main.ml
@@ -444,10 +444,12 @@ let turtle_test_case =
(* TODO This test works as follows: we take a turtle string and create a graph out of it using rdf_turtle.decode,
* which is the composition of the turtle parser, and the transformation which transforms instances of the turtle type into a graph.
* We compare the result to a graph which the empty graph with a number of triples added.
+ * The triples are added using the transformation from "https://www.easyrdf.org/converter"
+ * and some from the tests from "https://w3c.github.io/rdf-tests/turtle/".
* We have some helper functions to reduce the amount of code.
* One issue with this approach is, is that when there are tests that don't pass. it is not
* immediately clear where the problems lie, since the decode function is a composition of other
- * (already quite complicated) funtions. *)
+ * (already quite complicated) functions. *)
let turtle_to_graph_test_case =
(* A triple of three Iri's *)
let triple_of_iri_iri_iri sub pred obj =
@@ -705,22 +707,53 @@ let turtle_to_graph_test_case =
"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 . ", *)
+ (* TODO: this test fails. That is because the base uri is not used yet, I think. *)
+ (* " @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/> .
+ @prefix rel: <http://www.perceive.net/schemas/relationship/> .
+
+ <#green-goblin>
+ rel:enemyOf <#spiderman> ; #LET us put a comment here
+ a foaf:Person ;
+ foaf:name \"Green Goblin\" .
+
+ <#spiderman>
+ rel:enemyOf <#green-goblin> ;
+ a foaf:Person ;
+ foaf:name \"Spiderman\", \"Человек-паук\"@ru . ",
+ Rdf.Graph.empty
+ |> Rdf.Graph.add (triple_of_iri_iri_iri
+ "http://example.org/#green-goblin"
+ "http://www.perceive.net/schemas/relationship/enemyOf"
+ "http://example.org/#spiderman")
+ |> Rdf.Graph.add (triple_of_iri_iri_iri
+ "http://example.org/#green-goblin"
+ a_pred
+ "http://xmlns.com/foaf/0.1/Person")
+ |> Rdf.Graph.add (triple_of_iri_iri_literal
+ "http://example.org/#green-goblin"
+ "http://xmlns.com/foaf/0.1/name"
+ "Green Goblin")
+ |> Rdf.Graph.add (triple_of_iri_iri_iri
+ "http://example.org/#spiderman"
+ "http://www.perceive.net/schemas/relationship/enemyOf"
+ "http://example.org/#green-goblin")
+ |> Rdf.Graph.add (triple_of_iri_iri_iri
+ "http://example.org/#spiderman"
+ a_pred
+ "http://xmlns.com/foaf/0.1/Person")
+ |> Rdf.Graph.add (triple_of_iri_iri_literal
+ "http://example.org/#spiderman"
+ "http://xmlns.com/foaf/0.1/name"
+ "Spiderman")
+ |> Rdf.Graph.add (triple_of_iri_iri_literal
+ "http://example.org/#spiderman"
+ "http://xmlns.com/foaf/0.1/name"
+ ~obj_language:"ru"
+ "Человек-паук")
+ ; *)
] in
test_case "turtle parser and transform" `Quick
(fun () ->