educelab-hercdb 0.1.0.dev1__tar.gz → 0.1.0.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: educelab-hercdb
3
- Version: 0.1.0.dev1
3
+ Version: 0.1.0.dev2
4
4
  Summary: Graph database API for Herculaneum data
5
5
  Author-email: Mami Hayashida <mami.hayashida@uky.edu>, Seth Parker <c.seth.parker@uky.edu>
6
6
  Project-URL: Repository, https://gitlab.com/educelab/herculaneum-graph-db
@@ -8,7 +8,7 @@ include = ["educelab.hercdb"]
8
8
 
9
9
  [project]
10
10
  name = "educelab-hercdb"
11
- version = "0.1.0.dev1"
11
+ version = "0.1.0.dev2"
12
12
  dependencies = [
13
13
  "neo4j>=5.20",
14
14
  "numpy>=2.0",
@@ -0,0 +1,3 @@
1
+ from educelab.hercdb import config
2
+ from educelab.hercdb.api import (connect, GraphDBConnection, FlatbedScanType,
3
+ PGSRawType, SpectralRawType)
@@ -1,5 +1,4 @@
1
1
  import logging
2
- from typing import Optional
3
2
  from enum import Enum
4
3
 
5
4
  from neo4j import GraphDatabase
@@ -19,7 +18,7 @@ PGSRawType = DatasetType.PGSRaw
19
18
  SpectralRawType = DatasetType.SpectralRaw
20
19
 
21
20
 
22
- class _GraphConnector:
21
+ class GraphDBConnection:
23
22
  logger = logging.getLogger('hercdb.connector')
24
23
  uri: str = None
25
24
  user: str = None
@@ -35,11 +34,15 @@ class _GraphConnector:
35
34
  def close(self):
36
35
  self.driver.close()
37
36
 
38
- def verify_conn(self):
39
- self.driver.verify_connectivity()
40
- self.logger.info(f"connected to {self.uri} as '{self.user}'")
37
+ def verify_connection(self):
38
+ try:
39
+ self.driver.verify_connectivity()
40
+ return True
41
+ except Exception as e:
42
+ self.logger.debug('failed to connect', exc_info=e)
43
+ return False
41
44
 
42
- def delete_all(self):
45
+ def _delete_all(self):
43
46
  records, summary, keys = self.driver.execute_query(
44
47
  """
45
48
  MATCH (n)
@@ -48,7 +51,7 @@ class _GraphConnector:
48
51
  database_="neo4j",
49
52
  )
50
53
 
51
- def return_all(self):
54
+ def _return_all(self):
52
55
  records, summary, keys = self.driver.execute_query(
53
56
  """
54
57
  MATCH (n)
@@ -60,7 +63,7 @@ class _GraphConnector:
60
63
  self.logger.debug(summary)
61
64
  self.logger.debug(keys)
62
65
 
63
- def node_count(self) -> int:
66
+ def _node_count(self) -> int:
64
67
  record, keys, summary = self.driver.execute_query(
65
68
  """
66
69
  MATCH (n)
@@ -90,7 +93,7 @@ class _GraphConnector:
90
93
  pherc_n = records[0]["ph.human_name"]
91
94
  corn_n = records[0]["c.human_name"]
92
95
 
93
- if pezzo:
96
+ if pezzo is not None:
94
97
  # Currently this is irrelevant since there are no pezzo with "names"
95
98
  records, summary, keys = self.driver.execute_query(
96
99
  """
@@ -168,11 +171,7 @@ class _GraphConnector:
168
171
  return properties
169
172
 
170
173
 
171
- # Server connector instance
172
- _connector: Optional[_GraphConnector] = None
173
-
174
-
175
- def connect(uri=None, user=None, password=None) -> bool:
174
+ def connect(uri=None, user=None, password=None) -> GraphDBConnection:
176
175
  # use system config values if not provided
177
176
  from educelab.hercdb import config
178
177
  if uri is None:
@@ -182,51 +181,6 @@ def connect(uri=None, user=None, password=None) -> bool:
182
181
  if password is None:
183
182
  password = config.password
184
183
 
185
- # close existing connection
186
- global _connector
187
- if _connector is not None:
188
- disconnect()
189
-
190
184
  # open new connection
191
- _connector = _GraphConnector(uri, user, password)
192
- return verify_connection()
193
-
194
-
195
- def disconnect():
196
- global _connector
197
- if _connector is not None:
198
- _connector.close()
199
- _connector = None
200
-
201
-
202
- def verify_connection() -> bool:
203
- if _connector is None:
204
- return False
205
- try:
206
- _connector.verify_conn()
207
- return True
208
- except Exception as e:
209
- logging.getLogger(__name__).debug('failed to connect', exc_info=e)
210
- return False
211
-
212
-
213
- def node_count() -> int:
214
- if _connector is None:
215
- return -1
216
- else:
217
- return _connector.node_count()
218
-
219
-
220
- def get_display_name(*args, **kwargs):
221
- if _connector is not None:
222
- return _connector.get_human_readable_name(*args, **kwargs)
223
-
224
-
225
- def list_cornici_pezzi(*args, **kwargs):
226
- if _connector is not None:
227
- return _connector.list_cornici_pezzi(*args, **kwargs)
228
-
229
-
230
- def find_datasets(*args, **kwargs):
231
- if _connector is not None:
232
- return _connector.find_datasets(*args, **kwargs)
185
+ db = GraphDBConnection(uri, user, password)
186
+ return db
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: educelab-hercdb
3
- Version: 0.1.0.dev1
3
+ Version: 0.1.0.dev2
4
4
  Summary: Graph database API for Herculaneum data
5
5
  Author-email: Mami Hayashida <mami.hayashida@uky.edu>, Seth Parker <c.seth.parker@uky.edu>
6
6
  Project-URL: Repository, https://gitlab.com/educelab/herculaneum-graph-db
@@ -1,6 +0,0 @@
1
- from educelab.hercdb import config
2
- from educelab.hercdb.api import (connect, node_count, disconnect,
3
- list_cornici_pezzi, find_datasets,
4
- get_display_name, verify_connection)
5
-
6
- from educelab.hercdb.api import (FlatbedScanType, PGSRawType, SpectralRawType)