RDF.Query.execute

You're seeing just the function execute, go back to RDF.Query module for more information.
Link to this function

execute(query, graph, opts \\ [])

View Source

Execute the given query against the given graph.

The query can be given directly as RDF.Query.BGP struct created with one of the builder functions in this module or as basic graph pattern expression accepted by bgp/1.

The result is a list of maps with the solutions for the variables in the graph pattern query and will be returned in a :ok tuple. In case of an error a :error tuple is returned.

Example

Let's assume we have an example_graph with these triples:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex:   <http://example.com/> .

ex:Outlaw
  foaf:name   "Johnny Lee Outlaw" ;
  foaf:mbox   <mailto:jlow@example.com> .

ex:Goodguy
  foaf:name   "Peter Goodguy" ;
  foaf:mbox   <mailto:peter@example.org> ;
  foaf:friend ex:Outlaw .
iex> {:_, FOAF.name, :name?} |> RDF.Query.execute(example_graph())
{:ok, [%{name: ~L"Peter Goodguy"}, %{name: ~L"Johnny Lee Outlaw"}]}

iex> [
...>   {:_, FOAF.name, :name?},
...>   {:_, FOAF.mbox, :mbox?},
...> ] |> RDF.Query.execute(example_graph())
{:ok, [
  %{name: ~L"Peter Goodguy", mbox: ~I<mailto:peter@example.org>},
  %{name: ~L"Johnny Lee Outlaw", mbox: ~I<mailto:jlow@example.com>}
]}

iex> query = [
...>   {:_, FOAF.name, :name?},
...>   {:_, FOAF.mbox, :mbox?},
...> ] |> RDF.Query.bgp()
...> RDF.Query.execute(query, example_graph())
{:ok, [
  %{name: ~L"Peter Goodguy", mbox: ~I<mailto:peter@example.org>},
  %{name: ~L"Johnny Lee Outlaw", mbox: ~I<mailto:jlow@example.com>}
]}

iex> [
...>   EX.Goodguy, FOAF.friend, FOAF.name, :name?
...> ] |> RDF.Query.path() |> RDF.Query.execute(example_graph())
{:ok, [%{name: ~L"Johnny Lee Outlaw"}]}