aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-06-22 15:27:08 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:04:42 +0200
commitb7ff36ebe39b28fd6906ea47925809f7551c5535 (patch)
tree77f85bc5bc4d90739757036aa0fc651eca5ad408
parentb3a7faa0624dd8890ed3ba0e34eef3a0f8080323 (diff)
Add decode function
-rw-r--r--lib/turtle/rdf_turtle.ml26
-rw-r--r--lib/turtle/rdf_turtle.mli2
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
index e7c5152..1412a43 100644
--- a/lib/turtle/rdf_turtle.ml
+++ b/lib/turtle/rdf_turtle.ml
@@ -27,7 +27,6 @@ let iri_of_resource : Ast.parser_state -> Ast.Iri.t -> Iri.t = fun
| Iriref str ->
str |> Iri.of_string
| Prefixed_name (a, b) ->
-
Iri.of_string (a ^ b)
(* TODO what should this be? *)
@@ -202,6 +201,31 @@ let apply_statement : ctxG -> Ast.Statement.t -> ctxG =
let sub_bnode = Triple.Subject.of_blank_node @@ bnode in
List.fold_left (insert_sub_predobj sub_bnode) (ctx, g) predobjs
+let apply_statements : ctxG -> Ast.Turtle.t -> ctxG =
+ fun (ctx, g) statements ->
+ List.fold_left apply_statement (ctx, g) statements
+
+let parse p =
+ Angstrom.parse_string
+ ~consume:Angstrom.Consume.All
+ p
+
+let decode str =
+ let ctx : Ast.parser_state = {
+ base_uri = "base" |> Iri.of_string;
+ namespaces = Ast.SMap.empty;
+ bnode_labels = Ast.SMap.empty;
+ } in
+ let g = Graph.empty in
+ str
+ |> parse Parser.turtle
+ |> (function
+ | Ok x ->
+ apply_statements (ctx, g) x
+ |> (fun (_ctx, g) -> g)
+ | Error e -> raise (Failure (Fmt.str "eror: %s@." e)))
+
+
(* SUBJECT COLLECTIONS *)
(* <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://a.example/p> <http://a.example/o> . *)
(* *)
diff --git a/lib/turtle/rdf_turtle.mli b/lib/turtle/rdf_turtle.mli
index 03f754d..27590ca 100644
--- a/lib/turtle/rdf_turtle.mli
+++ b/lib/turtle/rdf_turtle.mli
@@ -278,3 +278,5 @@ end
type ctxG = Ast.parser_state * Rdf.Graph.t
val apply_statement : ctxG -> Ast.Statement.t -> ctxG
+
+val decode : string -> Rdf.Graph.t