diff --git a/CHANGELOG.md b/CHANGELOG.md index fc5fbb5..11f6c46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and ### Added - support for `RDF.PropertyMap` on `RDF.Statement.new/2` and `RDF.Statement.coerce/2` +- `RDF.Dataset.graph_count/1` ### Changed diff --git a/lib/rdf/dataset.ex b/lib/rdf/dataset.ex index 9172e2f..b5ca19c 100644 --- a/lib/rdf/dataset.ex +++ b/lib/rdf/dataset.ex @@ -532,6 +532,24 @@ defmodule RDF.Dataset do end end + @doc """ + The number of graphs within a `RDF.Dataset`. + + ## Examples + + iex> RDF.Dataset.new([ + ...> {EX.S1, EX.p1, EX.O1}, + ...> {EX.S2, EX.p2, EX.O2}, + ...> {EX.S1, EX.p2, EX.O3, EX.Graph}]) + ...> |> RDF.Dataset.graph_count() + 2 + + """ + @spec graph_count(t) :: non_neg_integer + def graph_count(%__MODULE__{} = dataset) do + Enum.count(dataset.graphs) + end + @doc """ The number of statements within a `RDF.Dataset`.