EdgeInstance.set()#
relationalai.std.graphs
#EdgeInstance.set(**kwargs) -> EdgeInstance
Sets properties on an EdgeInstance
object and returns the EdgeInstance
.
Note that unlike Instance.set()
,
you can’t set a Type
on an edge.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
*kwargs | Any | Properties and values to set on the EdgeInstance . |
Returns#
An EdgeInstance
object.
Example#
#import relationalai as rai
from relationalai.std.graphs import Graph
# Create a model with a 'Person' type.
model = rai.Model("socialNetwork")
Person = model.Type("Person")
# Add people to the model connected by a multi-valued 'follows' property.
with model.rule():
alice = Person.add(name="Alice")
bob = Person.add(name="Bob")
alice.follows.add(bob)
# Create a directed graph with 'Person' nodes and 'follows' edges.
graph = Graph(model)
graph.Edge.extend(Person.follows)
# Set the 'color' property of all edges to 'red'.
with model.rule():
edge = graph.Edge()
edge.set(color="red")
# Query the edges in the graph.
with model.query() as select:
edge = graph.Edge()
response = select(edge.from_.name, edge.to.name, edge.color)
print(response.results)
# Output:
# name name2 v
# 0 Alice Bob red