Domain Relations

Standard relationship types for knowledge and structure graphs

KnowledgeRelations

Registry of standard edge types for knowledge domain graphs. These constants ensure consistent relationship naming across plugins and UIs.

Common patterns: - Person -> AUTHORED -> Work - Work -> DISCUSSES -> Topic - Work -> MENTIONS -> Person/Concept - Work -> DEFINES -> Concept - Concept -> RELATED_TO -> Concept - Work -> QUOTES -> Quote


source

KnowledgeRelations


def KnowledgeRelations(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Registry of standard edge types for knowledge graphs.


source

KnowledgeRelations.all


def all(
    
)->list: # List of all relation type strings

Return all defined relation types.

# List all available relation types
print("Available relations:")
for rel in KnowledgeRelations.all():
    print(f"  - {rel}")
Available relations:
  - AUTHORED
  - DISCUSSES
  - MENTIONS
  - DEFINES
  - RELATED_TO
  - QUOTES
# Use relation constants directly
print(f"AUTHORED: {KnowledgeRelations.AUTHORED}")
print(f"MENTIONS: {KnowledgeRelations.MENTIONS}")
AUTHORED: AUTHORED
MENTIONS: MENTIONS

Example: Creating Edges with Relations

from uuid import uuid4
from cjm_graph_plugin_system.core import GraphEdge
from cjm_graph_domains.domains.knowledge import Person, Work, Concept, Quote

# Create domain nodes
author = Person(name="Sun Tzu")
book = Work(title="The Art of War")
concept = Concept(name="Deception")
quote = Quote(text="All warfare is based on deception.")

# Create edges using standard relation types
edges = [
    GraphEdge(
        id=str(uuid4()),
        source_id=author.id,
        target_id=book.id,
        relation_type=KnowledgeRelations.AUTHORED
    ),
    GraphEdge(
        id=str(uuid4()),
        source_id=book.id,
        target_id=concept.id,
        relation_type=KnowledgeRelations.DEFINES
    ),
    GraphEdge(
        id=str(uuid4()),
        source_id=book.id,
        target_id=quote.id,
        relation_type=KnowledgeRelations.QUOTES
    )
]

print(f"Created {len(edges)} edges:")
for edge in edges:
    print(f"  - {edge.relation_type}")
Created 3 edges:
  - AUTHORED
  - DEFINES
  - QUOTES

StructureRelations

Registry of standard edge types for content structure graphs. These relations define how documents and segments are connected to form a traversable “narrative spine”.

Common patterns: - Document -> STARTS_WITH -> Segment (entry point) - Segment -> NEXT -> Segment (sequential traversal) - Segment -> PART_OF -> Document (containment)


source

StructureRelations


def StructureRelations(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Registry of standard edge types for content structure graphs.


source

StructureRelations.all


def all(
    
)->list: # List of all relation type strings

Return all defined relation types.

# List all structure relation types
print("Structure relations:")
for rel in StructureRelations.all():
    print(f"  - {rel}")
Structure relations:
  - NEXT
  - PART_OF
  - STARTS_WITH
# Use relation constants directly
print(f"NEXT: {StructureRelations.NEXT}")
print(f"PART_OF: {StructureRelations.PART_OF}")
print(f"STARTS_WITH: {StructureRelations.STARTS_WITH}")
NEXT: NEXT
PART_OF: PART_OF
STARTS_WITH: STARTS_WITH

Example: Building a Narrative Spine

This example demonstrates creating edges that form a traversable document structure.

from cjm_graph_domains.domains.structure import Document, Segment

# Create document and segments
doc = Document(title="1. Laying Plans", media_type="audio")
segments = [
    Segment(text="Laying Plans", index=0, role="title"),
    Segment(text="Sun Tzu said,", index=1),
    Segment(text="The art of war is of vital importance to the state.", index=2),
]

# Build the narrative spine edges
edges = []

# Document entry point: STARTS_WITH first segment
edges.append(GraphEdge(
    id=str(uuid4()),
    source_id=doc.id,
    target_id=segments[0].id,
    relation_type=StructureRelations.STARTS_WITH
))

# Sequential links: NEXT between consecutive segments
for i in range(len(segments) - 1):
    edges.append(GraphEdge(
        id=str(uuid4()),
        source_id=segments[i].id,
        target_id=segments[i + 1].id,
        relation_type=StructureRelations.NEXT
    ))

# Containment: each segment PART_OF document
for seg in segments:
    edges.append(GraphEdge(
        id=str(uuid4()),
        source_id=seg.id,
        target_id=doc.id,
        relation_type=StructureRelations.PART_OF
    ))

print(f"Created {len(edges)} structure edges:")
for edge in edges:
    print(f"  - {edge.relation_type}")
Created 6 structure edges:
  - STARTS_WITH
  - NEXT
  - NEXT
  - PART_OF
  - PART_OF
  - PART_OF