|
import streamlit as st |
|
from py2neo import Graph, Node, Relationship |
|
from scripts.viz import draw |
|
|
|
|
|
graph = Graph() |
|
graph.delete_all() |
|
|
|
|
|
nicole = Node("Person", name="Nicole", age=24) |
|
drew = Node("Person", name="Drew", age=20) |
|
mtdew = Node("Drink", name="Mountain Dew", calories=9000) |
|
cokezero = Node("Drink", name="Coke Zero", calories=0) |
|
coke = Node("Manufacturer", name="Coca Cola") |
|
pepsi = Node("Manufacturer", name="Pepsi") |
|
|
|
graph.create(nicole | drew | mtdew | cokezero | coke | pepsi) |
|
graph.create(Relationship(nicole, "LIKES", cokezero)) |
|
graph.create(Relationship(nicole, "LIKES", mtdew)) |
|
graph.create(Relationship(drew, "LIKES", mtdew)) |
|
graph.create(Relationship(coke, "MAKES", cokezero)) |
|
graph.create(Relationship(pepsi, "MAKES", mtdew)) |
|
|
|
|
|
st.title("Py2neo Application with Streamlit") |
|
|
|
|
|
st.subheader("Graph Visualization") |
|
options = {"Person": "name", "Drink": "name", "Manufacturer": "name"} |
|
draw(graph, options) |
|
|
|
|
|
st.subheader("Node and Relationship Information") |
|
st.write("Nodes:") |
|
for node in [nicole, drew, mtdew, cokezero, coke, pepsi]: |
|
st.write(f"{node.labels}: {node}") |
|
|
|
st.write("Relationships:") |
|
for relationship in graph.match(rel_type="LIKES"): |
|
st.write(relationship) |
|
|
|
st.write("Manufacturers:") |
|
for manufacturer in graph.match(rel_type="MAKES"): |
|
st.write(manufacturer) |