graph
relationalai.semantics.reasoners
Graph reasoning: model graphs and run graph algorithms in PyRel.
Provides a declarative Python API for constructing directed or undirected,
weighted or unweighted graphs in a Model and running algorithms
over them.
This package is intentionally lightweight at the import surface: Graph is
the main entry point, and algorithm-level details are documented on each
Graph method.
Quick Start
Section titled “Quick Start”Build a small directed graph and compute node outdegree.
from relationalai.semantics import Model, Integerfrom relationalai.semantics.reasoners.graph import Graph
model = Model("quick_start")graph = Graph(model, directed=True, weighted=False)Node, Edge = graph.Node, graph.Edge
n1 = Node.new(id=1)n2 = Node.new(id=2)n3 = Node.new(id=3)n4 = Node.new(id=4)
model.define(n1, n2, n3, n4)
model.define( Edge.new(src=n1, dst=n2), Edge.new(src=n2, dst=n3), Edge.new(src=n3, dst=n1), Edge.new(src=n3, dst=n4),)
outdegree = graph.outdegree()model.select(Node.id, Integer).where(outdegree(Node, Integer)).inspect()Classes
Section titled “Classes”Classes exposed by this module.
Graph A graph defined within a PyRel model, over which graph algorithms can be computed. Re-exported from
relationalai.semantics.reasoners.graph.core. Modules and Subpackages
Section titled “Modules and Subpackages”Submodules and subpackages available under this namespace.
core Core functionality for the graphs package.