Skip to content

Commit bb33368

Browse files
Merge pull request #14 from esteinholtz-cloudera/json2html_conv
added utility tool to convert from JSON to HTML
2 parents 89dc741 + ba76390 commit bb33368

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

json_to_html.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Utility script to convert existing JSON knowledge graph data to HTML visualization.
4+
This allows testing the visualization features without running the full pipeline.
5+
"""
6+
7+
import json
8+
import sys
9+
import os
10+
11+
# Add the src directory to Python path so we can import our modules
12+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
13+
14+
from knowledge_graph.visualization import visualize_knowledge_graph
15+
16+
def json_to_html(json_file, output_file):
17+
"""
18+
Convert JSON knowledge graph data to HTML visualization.
19+
20+
Args:
21+
json_file: Path to JSON file containing triples data
22+
output_file: Path to save the HTML visualization
23+
"""
24+
try:
25+
# Load JSON data
26+
with open(json_file, 'r', encoding='utf-8') as f:
27+
triples = json.load(f)
28+
29+
print(f"Loaded {len(triples)} triples from {json_file}")
30+
31+
# Generate HTML visualization
32+
stats = visualize_knowledge_graph(triples, output_file)
33+
34+
print(f"Generated HTML visualization: {output_file}")
35+
print("Graph Statistics:")
36+
print(f" Nodes: {stats['nodes']}")
37+
print(f" Edges: {stats['edges']}")
38+
print(f" Original Edges: {stats.get('original_edges', 'N/A')}")
39+
print(f" Inferred Edges: {stats.get('inferred_edges', 'N/A')}")
40+
print(f" Communities: {stats['communities']}")
41+
42+
print(f"\nTo view the visualization, open: file://{os.path.abspath(output_file)}")
43+
44+
except Exception as e:
45+
print(f"Error: {e}")
46+
sys.exit(1)
47+
48+
if __name__ == "__main__":
49+
if len(sys.argv) != 3:
50+
print("Usage: python json_to_html.py <input.json> <output.html>")
51+
print("Example: python json_to_html.py docs/industrialRev.json test_inferred_filter.html")
52+
sys.exit(1)
53+
54+
json_file = sys.argv[1]
55+
output_file = sys.argv[2]
56+
57+
json_to_html(json_file, output_file)

0 commit comments

Comments
 (0)