|
2 | 2 | import time
|
3 | 3 | import threading
|
4 | 4 | from queue import Queue
|
5 |
| -from neo4j import GraphDatabase |
6 | 5 | import math
|
7 | 6 | import sys
|
8 | 7 |
|
9 |
| -class IEEEImporter(object): |
| 8 | +from util.graphdb_base import GraphDBBase |
10 | 9 |
|
11 |
| - def __init__(self, uri, user, password): |
12 |
| - self._driver = GraphDatabase.driver(uri, auth=(user, password), encrypted=0) |
| 10 | +class IEEEImporter(GraphDBBase): |
| 11 | + |
| 12 | + def __init__(self, argv): |
| 13 | + super().__init__(command=__file__, argv=argv) |
13 | 14 | self._transactions = Queue()
|
14 | 15 | self._dictionaries = {}
|
15 | 16 | self._print_lock = threading.Lock()
|
16 | 17 | with self._driver.session() as session:
|
17 |
| - self.executeNoException(session, "CREATE CONSTRAINT ON (s:Transaction) ASSERT s.transactionId IS UNIQUE") |
18 |
| - self.executeNoException(session, "CREATE INDEX ON :Transaction(isFraud)") |
19 |
| - self.executeNoException(session, "CREATE INDEX ON :Transaction(isTrain)") |
| 18 | + self.execute_without_exception("CREATE CONSTRAINT ON (s:Transaction) ASSERT s.transactionId IS UNIQUE") |
| 19 | + self.execute_without_exception("CREATE INDEX ON :Transaction(isFraud)") |
| 20 | + self.execute_without_exception("CREATE INDEX ON :Transaction(isTrain)") |
20 | 21 |
|
21 | 22 | def close(self):
|
22 |
| - self._driver.close() |
| 23 | + self.close() |
23 | 24 |
|
24 | 25 | def import_transaction(self, directory):
|
25 | 26 | j = 0
|
@@ -113,26 +114,16 @@ def write_transaction(self):
|
113 | 114 | print(e, row)
|
114 | 115 | self._transactions.task_done()
|
115 | 116 |
|
116 |
| - def executeNoException(self, session, query): |
117 |
| - try: |
118 |
| - session.run(query) |
119 |
| - except Exception as e: |
120 |
| - pass |
121 |
| - |
122 |
| - |
123 |
| -def strip(string): return ''.join([c if 0 < ord(c) < 128 else ' ' for c in string]) |
124 |
| - |
125 | 117 |
|
126 | 118 | if __name__ == '__main__':
|
127 |
| - uri = "bolt://localhost:7687" |
128 |
| - importer = IEEEImporter(uri=uri, user="neo4j", password="q1") |
| 119 | + importer = IEEEImporter(sys.argv[1:]) |
129 | 120 |
|
130 | 121 | start = time.time()
|
131 |
| - base_path = "/Users/ale/neo4j-servers/gpml/dataset/ieee/" |
132 |
| - if len(sys.argv) > 1: |
133 |
| - base_path = sys.argv[1] |
| 122 | + base_path = importer.source_dataset_path |
| 123 | + if not base_path: |
| 124 | + base_path = "../../../dataset/ieee" |
134 | 125 | importer.import_transaction(directory=base_path)
|
135 |
| - print("Time to complete paysim ingestion:", time.time() - start) |
| 126 | + print("Time to complete IEEE ingestion:", time.time() - start) |
136 | 127 |
|
137 | 128 | # intermediate = time.time()
|
138 | 129 | # importer.post_processing(sess_clicks=sessions)
|
|
0 commit comments