File size: 1,381 Bytes
5baef2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from db.neo4j_store import Neo4jStore


def print_node(data):

    if not data:
        print("Node not found")
        return

    print("\n" + "=" * 80)
    print("NODE")
    print("=" * 80)

    for k, v in data["node"].items():
        print(f"{k}: {v}")

    print("\n" + "=" * 80)
    print("NEIGHBORS")
    print("=" * 80)

    for neighbor in data["neighbors"]:

        relation = neighbor.get(
            "relation"
        )

        node = neighbor.get(
            "neighbor"
        )

        print(f"\n[{relation}]")

        if node:

            for k, v in node.items():

                if k == "text":

                    print(
                        f"{k}: "
                        f"{str(v)[:300]}"
                    )

                else:

                    print(
                        f"{k}: {v}"
                    )


def main():

    graph = Neo4jStore(
        uri="bolt://localhost:7687",
        username="neo4j",
        password="test12345"
    )

    while True:

        node_id = input(
            "\nEnter node id "
            "(or quit): "
        )

        if node_id.lower() == "quit":
            break

        result = (
            graph.get_node_with_neighbors(
                node_id
            )
        )

        print_node(
            result
        )

    graph.close()


if __name__ == "__main__":
    main()