java.lang.Object
com.darkcollective.relix.symbol.graph.SchemaGraph

public final class SchemaGraph extends Object
The schema graph: an immutable set of Relationship edges between relations.

The graph is a persistent value — with(Relationship) and merge(SchemaGraph) return new graphs, never mutate. This fits the REPL's accumulate-and-reanalyze session model: declared edges are rebuilt from source on every analysis, while edges learned during the session (conversational acquisition, joins observed in user queries) are merged in as a supplemental graph each time.

Merging deduplicates edges by name and endpoints (direction-insensitively — an edge and its reversal are the same relationship walked both ways). On a duplicate, the more authoritative EdgeOrigin wins: DECLARED over LEARNED over INFERRED; on an origin tie, this graph's edge is kept.

  • Field Details

    • EMPTY

      public static final SchemaGraph EMPTY
      The empty graph — the default on every SemanticModel.
  • Method Details

    • of

      public static SchemaGraph of(List<Relationship> relationships)
      Creates a graph holding the given relationships (order preserved).
    • relationships

      public List<Relationship> relationships()
      All edges of this graph, in insertion order.
    • isEmpty

      public boolean isEmpty()
      Returns true if this graph has no edges.
    • edgesOf

      public List<Relationship> edgesOf(RelationSymbol relation)
      All edges incident on the given relation, regardless of which endpoint holds it — every edge is walkable in both directions.
    • with

      public SchemaGraph with(Relationship relationship)
      Returns a new graph with the given edge added (deduplicating as merge(com.darkcollective.relix.symbol.graph.SchemaGraph)).
    • merge

      public SchemaGraph merge(SchemaGraph other)
      Returns a new graph containing this graph's edges plus other's, deduplicated by identity (name + unordered endpoints); the more authoritative origin wins a duplicate, this graph's edge wins a tie.
    • key

      public static String key(RelationSymbol relation)
      The lookup key of a relation in this graph: its namespace plus canonical (lower-cased) name. Stable across distinct symbol instances for the same relation.
    • toString

      public String toString()
      Overrides:
      toString in class Object