This project demonstrates how to create, query, and visualize a small graph using MeTTa and AtomSpace via the Hyperon Python bindings.
-
Graph Construction:
The script builds a simple directed graph representing relationships (e.g., "Alice knows Bob") using MeTTa code. It inserts nodes and links into AtomSpace through the Hyperon Python API. -
AtomSpace Querying:
It attempts to read back the graph structure (OrderedLink atoms) from AtomSpace using several fallback methods, adapting to different Hyperon/MeTTa API versions. -
Visualization:
The recovered graph triples are converted into a DOT graph and rendered as a PNG image using thegraphvizPython package. -
Export:
The script saves the graph visualization asgraph.pngand the recovered triples astriples.json.
Below is an example of the generated graph:
- Python 3.8+
- hyperon Python package (
pip install hyperon) - graphviz Python package (
pip install graphviz) - System
graphvizinstalled for PNG rendering (sudo apt install graphvizon Ubuntu)
- Install dependencies:
pip install hyperon graphviz sudo apt install graphviz - Run the script:
python test.py - View the output files:
graph.png: Visual representation of the graphtriples.json: List of recovered triples
- The script is robust to changes in the Hyperon/MeTTa API and will fall back to local data if AtomSpace querying fails.
- You can modify the graph structure by editing the
tripleslist in the script.
