Repository navigation
Expand file tree
/
Copy pathschema_builder.py
More file actions
62 lines (44 loc) · 1.83 KB
/
Copy pathschema_builder.py
File metadata and controls
62 lines (44 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from .types_defs import (
NODE_SCHEMAS,
RELATIONSHIP_PROPERTY_SCHEMAS,
RELATIONSHIP_SCHEMAS,
NodeSchema,
RelationshipPropertySchema,
RelationshipSchema,
)
def _format_node_schema(schema: NodeSchema) -> str:
return f"- {schema.label}: {schema.properties}"
def _format_relationship_schema(schema: RelationshipSchema) -> str:
sources = "|".join(str(s) for s in schema.sources)
targets = "|".join(str(t) for t in schema.targets)
if len(schema.sources) > 1:
sources = f"({sources})"
if len(schema.targets) > 1:
targets = f"({targets})"
return f"- {sources} -[:{schema.rel_type}]-> {targets}"
def build_node_labels_section() -> str:
lines = ["Node Labels and Their Key Properties:"]
lines.extend(_format_node_schema(schema) for schema in NODE_SCHEMAS)
return "\n".join(lines)
def build_relationships_section() -> str:
lines = ["Relationships (source)-[REL_TYPE]->(target):"]
lines.extend(_format_relationship_schema(schema) for schema in RELATIONSHIP_SCHEMAS)
return "\n".join(lines)
def _format_relationship_property_schema(schema: RelationshipPropertySchema) -> str:
types = "|".join(str(t) for t in schema.rel_types)
return f"- {types}: {schema.properties}"
def build_relationship_properties_section() -> str:
lines = [
"Relationship properties (one CALLS/REFERENCES/INSTANTIATES edge per "
"call site, one IMPORTS edge per bound name; use DISTINCT for endpoints):"
]
lines.extend(
_format_relationship_property_schema(schema)
for schema in RELATIONSHIP_PROPERTY_SCHEMAS
)
return "\n".join(lines)
def build_graph_schema_text() -> str:
return f"""{build_node_labels_section()}
{build_relationships_section()}
{build_relationship_properties_section()}"""
GRAPH_SCHEMA_DEFINITION = build_graph_schema_text()