# 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
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
Registry of standard edge types for knowledge graphs.
Return all defined relation types.
Available relations:
- AUTHORED
- DISCUSSES
- MENTIONS
- DEFINES
- RELATED_TO
- QUOTES
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
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)
Registry of standard edge types for content structure graphs.
Return all defined relation types.
Structure relations:
- NEXT
- PART_OF
- STARTS_WITH
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