aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2021-06-28 13:29:15 +0200
committerpukkamustard <pukkamustard@posteo.net>2021-06-28 13:29:15 +0200
commitb7732607fbaef6fca279200f01ec6df1015200e4 (patch)
tree5b4f94f3b74a44ea065b8151dfed551d75900045
parenta82f31e6c66ed56d53aad07c4d1d587d1280bf39 (diff)
Rdf.Graph: change argument order for mutating functions
-rw-r--r--lib/core/graph.ml14
-rw-r--r--lib/core/rdf.mli20
-rw-r--r--test/core/main.ml52
3 files changed, 44 insertions, 42 deletions
diff --git a/lib/core/graph.ml b/lib/core/graph.ml
index f1c0640..5d98842 100644
--- a/lib/core/graph.ml
+++ b/lib/core/graph.ml
@@ -30,13 +30,15 @@ let union a b =
left right))
a b
-let add graph (triple:Triple.t) =
+let add (triple:Triple.t) graph =
triple
|> singleton
|> union graph
-let add_seq graph triples =
- Seq.fold_left add graph triples
+let add_seq triples graph =
+ Seq.fold_left
+ (fun graph triple -> add triple graph)
+ graph triples
(* Remove object [o] from set of objects [os] but return None if resulting set is empty. *)
let remove_o o os =
@@ -58,7 +60,7 @@ let remove_p p o pos =
else
Some pos_removed
-let remove graph (triple:Triple.t) =
+let remove (triple:Triple.t) graph =
let s = triple.subject |> Triple.Subject.to_term in
let p = triple.predicate |> Triple.Predicate.to_term in
let o = triple.object' |> Triple.Object.to_term in
@@ -112,11 +114,11 @@ let to_triples graph =
TermMap.to_seq graph
|> _pos_seq_to_triples
-let to_triples_s graph subject =
+let to_triples_s subject graph =
TermMap.to_seq_from subject graph
|> _pos_seq_to_triples
-let to_triples_sp graph subject predicate =
+let to_triples_sp subject predicate graph =
match TermMap.find_opt subject graph with
| None -> Seq.empty
| Some pos ->
diff --git a/lib/core/rdf.mli b/lib/core/rdf.mli
index 97eebd0..90a3f5d 100644
--- a/lib/core/rdf.mli
+++ b/lib/core/rdf.mli
@@ -237,15 +237,15 @@ module Graph : sig
val union : t -> t -> t
(** [union a b] returns the union of the graphs. *)
- val add : t -> Triple.t -> t
- (** [add graph triple] returns a new graph containing [triple] (and everything in [graph]).*)
+ val add : Triple.t -> t -> t
+ (** [add triple graph] returns a new graph containing [triple] (and everything in [graph]).*)
- val add_seq : t -> Triple.t Seq.t -> t
- (** [add_seq graph triples] returns a new graph containing all triples in the
+ val add_seq : Triple.t Seq.t -> t -> t
+ (** [add_seq triples graph] returns a new graph containing all triples in the
sequence [triples]. *)
- val remove: t -> Triple.t -> t
- (** [remove_triple graph triple] removes [triple] from [graph]. *)
+ val remove: Triple.t -> t -> t
+ (** [remove_triple triple graph] removes [triple] from [graph]. *)
val subjects : t -> Term.t Seq.t
(** [subjects graph] returns a sequence of subjects that appear in the graph. *)
@@ -253,11 +253,11 @@ module Graph : sig
val to_triples: t -> Triple.t Seq.t
(** [to_triples graph] returns a sequence of triples in [graph].*)
- val to_triples_s : t -> Term.t -> Triple.t Seq.t
- (** [to_seq_s graph subject] returns a sequence of triples in [graph] with
+ val to_triples_s : Term.t -> t -> Triple.t Seq.t
+ (** [to_seq_s subject graph] returns a sequence of triples in [graph] with
[subject] in subject position.*)
- val to_triples_sp : t -> Term.t -> Term.t -> Triple.t Seq.t
- (** [to_seq_sp graph subject predicate] returns a sequence of triples in [graph] with
+ val to_triples_sp : Term.t -> Term.t -> t -> Triple.t Seq.t
+ (** [to_seq_sp subject predicate graph] returns a sequence of triples in [graph] with
[subject] in subject position and [predicate] in predicate position.*)
end
diff --git a/test/core/main.ml b/test/core/main.ml
index 5bf6987..0bf439c 100644
--- a/test/core/main.ml
+++ b/test/core/main.ml
@@ -25,42 +25,42 @@ module GraphTest = struct
check bool
"graph with one element added is not equal to empty graph"
false
- Rdf.Graph.(equal empty @@
- add empty Rdf.Triple.(
- make
- (Subject.of_iri @@ ex "foo")
- (Predicate.of_iri @@ ex "prop")
- (Object.of_iri @@ ex "bar")));
+ Rdf.Graph.(equal empty
+ (empty |> add Rdf.Triple.(make
+ (Subject.of_iri @@ ex "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar"))));
+
check bool
"graph with one element is equal"
true
Rdf.Graph.(equal
- (add empty
- Rdf.Triple.(make
- (Subject.of_iri @@ ex "foo")
- (Predicate.of_iri @@ ex "prop")
- (Object.of_iri @@ ex "bar")))
- (add empty
- Rdf.Triple.(make
- (Subject.of_iri @@ ex "foo")
- (Predicate.of_iri @@ ex "prop")
- (Object.of_iri @@ ex "bar"))));
+ (empty
+ |> add Rdf.Triple.(make
+ (Subject.of_iri @@ ex "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar")))
+ (empty
+ |> add Rdf.Triple.(make
+ (Subject.of_iri @@ ex "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar"))));
check bool
"graph with two different elements is not equal"
false
Rdf.Graph.(equal
- (add empty
- Rdf.Triple.(make
- (Subject.of_iri @@ ex "foo")
- (Predicate.of_iri @@ ex "prop")
- (Object.of_iri @@ ex "bar")))
- (add empty
- Rdf.Triple.(make
- (Subject.of_iri @@ ex2 "foo")
- (Predicate.of_iri @@ ex "prop")
- (Object.of_iri @@ ex "bar"))));
+ (empty
+ |> add Rdf.Triple.(make
+ (Subject.of_iri @@ ex "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar")))
+ (empty
+ |> add Rdf.Triple.(make
+ (Subject.of_iri @@ ex2 "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar"))));
)