GenAI.Graph.Link (GenAI Core v0.2.0)
Represent a link between two nodes in a graph.
Link to this section Summary
Functions
Obtain the description of a graph link.
Obtain the description of a graph link, or return a default value if the description is nil.
Obtain the handle of a graph link.
Obtain the handle of a graph link, or return a default value if the handle is nil.
Obtain the id of a graph link.
Obtain the label of a graph link.
Obtain the label of a graph link, or return a default value if the label is nil.
Obtain the name of a graph link.
Obtain the name of a graph link, or return a default value if the name is nil.
Create a new link.
Set the source connector of a graph link, if it is not already set.
Set the target connector of a graph link, if it is not already set.
Obtain the source connector of a graph link.
Obtain the target connector of a graph link.
Obtain the type of a graph link.
Obtain the type of a graph link, or return a default value if the type is nil.
Ensure the graph link has an id, generating one if necessary.
Link to this section Types
@type t() :: %GenAI.Graph.Link{ description: GenAI.Types.description(), handle: GenAI.Types.handle(), id: G.graph_id(), label: GenAI.Types.Graph.link_label(), meta: nil, name: GenAI.Types.name(), source: GenAI.Records.Link.connector(), target: GenAI.Records.Link.connector(), type: GenAI.Types.Graph.link_type(), vsn: float() }
Link to this section Functions
description(graph_link)
@spec description(graph_link :: GenAI.Types.Graph.graph_link()) :: GenAI.Types.result(GenAI.Types.description(), GenAI.Types.details())
Obtain the description of a graph link.
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, description: "B")
...> GenAI.Graph.Link.description(l)
{:ok, "B"}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> GenAI.Graph.Link.description(l)
{:error, {:description, :is_nil}}
description(graph_link, default)
@spec description( graph_link :: GenAI.Types.Graph.graph_link(), default :: GenAI.Types.description() ) :: GenAI.Types.result(GenAI.Types.description(), GenAI.Types.details())
Obtain the description of a graph link, or return a default value if the description is nil.
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, description: "B")
...> GenAI.Graph.Link.description(l, "default")
{:ok, "B"}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> GenAI.Graph.Link.description(l, "default")
{:ok, "default"}
handle(graph_link)
@spec handle(graph_link :: GenAI.Types.Graph.graph_link()) :: GenAI.Types.result(GenAI.Types.handle(), GenAI.Types.details())
Obtain the handle of a graph link.
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, handle: :foo)
...> GenAI.Graph.Link.handle(l)
{:ok, :foo}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> GenAI.Graph.Link.handle(l)
{:error, {:handle, :is_nil}}
handle(graph_link, default)
@spec handle( graph_link :: GenAI.Types.Graph.graph_link(), default :: GenAI.Types.handle() ) :: GenAI.Types.result(GenAI.Types.handle(), GenAI.Types.details())
Obtain the handle of a graph link, or return a default value if the handle is nil.
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, handle: :foo)
...> GenAI.Graph.Link.handle(l, :default)
{:ok, :foo}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> GenAI.Graph.Link.handle(l, :default)
{:ok, :default}
id(graph_link)
@spec id(graph_link :: GenAI.Types.Graph.graph_link()) :: GenAI.Types.result(GenAI.Types.Graph.graph_link_id(), GenAI.Types.details())
Obtain the id of a graph link.
Examples
when-set
when set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, handle: :foo, name: "A", description: "B")
...> GenAI.Graph.Link.id(l)
{:ok, l.id}
when-not-set
when not set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, handle: :foo, name: "A", description: "B") |> put_in([Access.key(:id)], nil)
...> GenAI.Graph.Link.id(l)
{:error, {:id, :is_nil}}
label(graph_link)
@spec label(t()) :: GenAI.Types.result(GenAI.Types.Graph.link_label(), GenAI.Types.details())
Obtain the label of a graph link.
examples
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, label: :some_label)
...> GenAI.Graph.Link.label(l)
{:ok, :some_label}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> GenAI.Graph.Link.label(l)
{:error, {:label, :is_nil}}
label(graph_link, default)
@spec label(t(), default :: any()) :: GenAI.Types.result(GenAI.Types.Graph.link_label(), GenAI.Types.details())
Obtain the label of a graph link, or return a default value if the label is nil.
examples
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, label: :my_label)
...> GenAI.Graph.Link.label(l, :default)
{:ok, :my_label}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> GenAI.Graph.Link.label(l, :default)
{:ok, :default}
name(graph_link)
@spec name(graph_link :: GenAI.Types.Graph.graph_link()) :: GenAI.Types.result(GenAI.Types.name(), GenAI.Types.details())
Obtain the name of a graph link.
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, name: "A")
...> GenAI.Graph.Link.name(l)
{:ok, "A"}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> GenAI.Graph.Link.name(l)
{:error, {:name, :is_nil}}
name(graph_link, default)
@spec name( graph_link :: GenAI.Types.Graph.graph_link(), default :: GenAI.Types.name() ) :: GenAI.Types.result(GenAI.Types.name(), GenAI.Types.details())
Obtain the name of a graph link, or return a default value if the name is nil.
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, name: "A")
...> GenAI.Graph.Link.name(l, "default")
{:ok, "A"}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> GenAI.Graph.Link.name(l, "default")
{:ok, "default"}
new(source, target, options \\ nil)
Create a new link.
Examples
iex> node1_id = UUID.uuid5(:oid, "node-1")
iex> node2_id = UUID.uuid5(:oid, "node-2")
iex> l = GenAI.Graph.Link.new(node1_id, node2_id, name: "Hello")
%GenAI.Graph.Link{
handle: nil,
name: "Hello",
description: nil,
source: R.Link.connector(node: ^node1_id, socket: :default, external: false),
target: R.Link.connector(node: ^node2_id, socket: :default, external: false),
vsn: 1.0
} = l
iex> node1_id = UUID.uuid5(:oid, "node-1")
iex> node2_id = UUID.uuid5(:oid, "node-2")
iex> l = GenAI.Graph.Link.new(R.Link.connector(node: node1_id, socket: :default, external: false), node2_id, handle: :andy)
%GenAI.Graph.Link{
handle: :andy,
source: R.Link.connector(node: ^node1_id, socket: :default, external: false),
target: R.Link.connector(node: ^node2_id, socket: :default, external: false),
vsn: 1.0
} = l
iex> node1_id = UUID.uuid5(:oid, "node-1")
iex> l = GenAI.Graph.Link.new(R.Link.connector(node: node1_id, socket: :default, external: false), nil, description: "A Node")
%GenAI.Graph.Link{
description: "A Node",
source: R.Link.connector(node: ^node1_id, socket: :default, external: false),
target: R.Link.connector(node: nil, socket: :default, external: true),
vsn: 1.0
} = l
# from node struct (requires protocol impl)
putnew_source(graph_link, source)
@spec putnew_source(graph_link :: GenAI.Types.Graph.graph_link(), source :: term()) :: GenAI.Types.Graph.graph_link()
Set the source connector of a graph link, if it is not already set.
Examples
when-not-set-by-id
When Not Set. By ID
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(nil, node2_id)
...> |> GenAI.Graph.Link.putnew_source(node1_id)
%GenAI.Graph.Link{source: R.Link.connector(node: ^node1_id, external: false)} = l
when-not-set-by-connector
When Not Set. By Connector
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(nil, node2_id)
...> |> GenAI.Graph.Link.putnew_source(R.Link.connector(node: node1_id, socket: :foo, external: false))
%GenAI.Graph.Link{source: R.Link.connector(node: ^node1_id, socket: :foo, external: false)} = l
when-set-by-id
When Set. By ID
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> node3_id = UUID.uuid5(:oid, "node-3")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> |> GenAI.Graph.Link.putnew_source(node3_id)
%GenAI.Graph.Link{source: R.Link.connector(node: ^node1_id, external: false)} = l
when-set-by-connector
When Set. By Connector
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> node3_id = UUID.uuid5(:oid, "node-3")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> |> GenAI.Graph.Link.putnew_source(R.Link.connector(node: node3_id, socket: :foo, external: false))
%GenAI.Graph.Link{source: R.Link.connector(node: ^node1_id, external: false)} = l
putnew_target(graph_link, target)
@spec putnew_target(graph_link :: GenAI.Types.Graph.graph_link(), target :: term()) :: GenAI.Types.Graph.graph_link()
Set the target connector of a graph link, if it is not already set.
Examples
when-not-set-by-id
When Not Set. By ID
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, nil)
...> |> GenAI.Graph.Link.putnew_target(node2_id)
%GenAI.Graph.Link{target: R.Link.connector(node: ^node2_id, external: false)} = l
when-not-set-by-connector
When Not Set. By Connector
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, nil)
...> |> GenAI.Graph.Link.putnew_target(R.Link.connector(node: node2_id, socket: :foo, external: false))
%GenAI.Graph.Link{target: R.Link.connector(node: ^node2_id, external: false)} = l
when-set-by-id
When Set. By ID
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> node3_id = UUID.uuid5(:oid, "node-3")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> |> GenAI.Graph.Link.putnew_target(node3_id)
%GenAI.Graph.Link{target: R.Link.connector(node: ^node2_id, external: false)} = l
when-set-by-connector
When Set. By Connector
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> node3_id = UUID.uuid5(:oid, "node-3")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> |> GenAI.Graph.Link.putnew_target(R.Link.connector(node: node3_id, socket: :foo, external: false))
%GenAI.Graph.Link{target: R.Link.connector(node: ^node2_id, external: false)} = l
source_connector(link)
@spec source_connector(graph_link :: GenAI.Types.Graph.graph_link()) :: GenAI.Types.result(GenAI.Records.Link.connector(), GenAI.Types.details())
Obtain the source connector of a graph link.
Examples
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> {:ok, sut} = GenAI.Graph.Link.source_connector(l)
...> sut
R.Link.connector(external: false) = sut
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> l = GenAI.Graph.Link.new(nil, node1_id)
...> {:ok, sut} = GenAI.Graph.Link.source_connector(l)
...> sut
R.Link.connector(external: true) = sut
target_connector(link)
@spec target_connector(graph_link :: GenAI.Types.Graph.graph_link()) :: GenAI.Types.result(GenAI.Records.Link.connector(), GenAI.Types.details())
Obtain the target connector of a graph link.
Examples
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> {:ok, sut} = GenAI.Graph.Link.target_connector(l)
...> sut
R.Link.connector(node: ^node2_id) = sut
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> l = GenAI.Graph.Link.new(node1_id, nil)
...> {:ok, sut} = GenAI.Graph.Link.target_connector(l)
...> sut
R.Link.connector(external: true) = sut
type(graph_link)
@spec type(t()) :: GenAI.Types.result(GenAI.Types.Graph.link_type(), GenAI.Types.details())
Obtain the type of a graph link.
examples
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, type: :link_type)
...> GenAI.Graph.Link.type(l)
{:ok, :link_type}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, type: nil)
...> GenAI.Graph.Link.type(l)
{:error, {:type, :is_nil}}
type(graph_link, default)
@spec type(t(), default :: any()) :: GenAI.Types.result(GenAI.Types.Graph.link_type(), GenAI.Types.details())
Obtain the type of a graph link, or return a default value if the type is nil.
examples
Examples
when-set
When Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, type: :link_type)
...> GenAI.Graph.Link.type(l, :default)
{:ok, :link_type}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id, type: nil)
...> GenAI.Graph.Link.type(l, :default)
{:ok, :default}
with_id(graph_link)
@spec with_id(graph_link :: GenAI.Types.Graph.graph_link()) :: GenAI.Types.result(GenAI.Types.Graph.graph_link(), GenAI.Types.details())
Ensure the graph link has an id, generating one if necessary.
Examples
when-already-set
When Already Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id)
...> {:ok, l2} = GenAI.Graph.Link.with_id(l)
...> %{was_nil: is_nil(l.id), is_nil: is_nil(l2.id), id_change: l.id != l2.id}
%{was_nil: false, is_nil: false, id_change: false}
when-not-set
When Not Set
iex> node1_id = UUID.uuid5(:oid, "node-1")
...> node2_id = UUID.uuid5(:oid, "node-2")
...> l = GenAI.Graph.Link.new(node1_id, node2_id) |> put_in([Access.key(:id)], nil)
...> {:ok, l2} = GenAI.Graph.Link.with_id(l)
...> %{was_nil: is_nil(l.id), is_nil: is_nil(l2.id), id_change: l.id != l2.id}
%{was_nil: true, is_nil: false, id_change: true}