GenAI.Graph.Link
(GenAI Core v0.3.1)
Copy Markdown
Represent a link between two nodes in a graph.
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.
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() }
Functions
@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
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
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}}
@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
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
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"}
@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
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
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}}
@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
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
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}
@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
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
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}}
@spec label(t()) :: GenAI.Types.result(GenAI.Types.Graph.link_label(), GenAI.Types.details())
Obtain the label of a graph link.
Examples
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
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}}
@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
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
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}
@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
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
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}}
@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
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
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"}
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)
@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
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)} = lWhen 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)} = lWhen 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)} = lWhen 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
@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
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)} = lWhen 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)} = lWhen 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)} = lWhen 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
@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
@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
@spec type(t()) :: GenAI.Types.result(GenAI.Types.Graph.link_type(), GenAI.Types.details())
Obtain the type of a graph link.
Examples
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
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}}
@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
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
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}
@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
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
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}