This repository was archived by the owner on May 17, 2026. It is now read-only.
forked from OHF-Voice/piper1-gpl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_puml.py
More file actions
50 lines (37 loc) · 1.49 KB
/
Copy pathgenerate_puml.py
File metadata and controls
50 lines (37 loc) · 1.49 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
import json
def generate_puml():
"""
Reads the JSON data and generates a PlantUML file.
"""
try:
with open('memory_valid.json', 'r') as f:
data = json.load(f)
except FileNotFoundError:
print("Error: memory_valid.json not found.")
return
except json.JSONDecodeError:
print("Error: Invalid JSON in memory_valid.json.")
return
puml_lines = ["@startuml"]
# First, define all the entities
for item in data:
if item.get('type') == 'entity':
name = item.get('name', 'Unnamed')
# Sanitize the name for use as an alias
alias = ''.join(e for e in name if e.isalnum() or e == '_')
puml_lines.append(f'object "{name}" as {alias}')
# Then, define all the relations
for item in data:
if item.get('type') == 'relation':
from_node = item.get('from', 'Unnamed')
to_node = item.get('to', 'Unnamed')
relation_type = item.get('relationType', 'relates')
from_alias = ''.join(e for e in from_node if e.isalnum() or e == '_')
to_alias = ''.join(e for e in to_node if e.isalnum() or e == '_')
puml_lines.append(f'{from_alias} --> {to_alias} : {relation_type}')
puml_lines.append("@enduml")
with open('knowledge_graph.puml', 'w') as f:
f.write('\n'.join(puml_lines))
print("Successfully generated knowledge_graph.puml")
if __name__ == "__main__":
generate_puml()