temporal-normalization-spacy 2.3.0__tar.gz → 2.4.0__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.
Files changed (22) hide show
  1. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/MANIFEST.in +1 -1
  2. {temporal_normalization_spacy-2.3.0/temporal_normalization_spacy.egg-info → temporal_normalization_spacy-2.4.0}/PKG-INFO +11 -10
  3. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/README.md +10 -9
  4. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/setup.py +2 -2
  5. temporal_normalization_spacy-2.3.0/temporal_normalization/libs/temporal-normalization-2.2.0.jar → temporal_normalization_spacy-2.4.0/temporal_normalization/libs/temporal-normalization-2.2.1.jar +0 -0
  6. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/process/java_process.py +84 -12
  7. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0/temporal_normalization_spacy.egg-info}/PKG-INFO +11 -10
  8. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization_spacy.egg-info/SOURCES.txt +1 -1
  9. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/LICENSE +0 -0
  10. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/setup.cfg +0 -0
  11. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/__init__.py +0 -0
  12. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/commons/__init__.py +0 -0
  13. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/commons/print_utils.py +0 -0
  14. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/commons/temporal_models.py +0 -0
  15. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/commons/temporal_types.py +0 -0
  16. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/factory.py +0 -0
  17. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/index.py +0 -0
  18. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization/process/__init__.py +0 -0
  19. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization_spacy.egg-info/dependency_links.txt +0 -0
  20. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization_spacy.egg-info/entry_points.txt +0 -0
  21. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization_spacy.egg-info/requires.txt +0 -0
  22. {temporal_normalization_spacy-2.3.0 → temporal_normalization_spacy-2.4.0}/temporal_normalization_spacy.egg-info/top_level.txt +0 -0
@@ -1,5 +1,5 @@
1
1
  include README.md
2
- include temporal_normalization/libs/temporal-normalization-2.2.0.jar
2
+ include temporal_normalization/libs/temporal-normalization-2.2.1.jar
3
3
 
4
4
  recursive-include temporal_normalizer/commons *
5
5
  recursive-include temporal_normalizer/libs *
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: temporal_normalization_spacy
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: A spaCy plugin for temporal normalization and extraction of historical dates in Romanian narrative texts.
5
5
  Home-page: https://github.com/iliedorobat/timespan-normalization-spacy
6
6
  Author: Ilie Cristian Dorobat
@@ -56,7 +56,7 @@ quality and reliability of date-related information extracted from text.
56
56
  <th>Examples of Temporal Expressions*</th>
57
57
  </tr>
58
58
  <tr>
59
- <td>dates</td>
59
+ <td>DATE</td>
60
60
  <td>
61
61
  YMD: 1881-08-31; 1857 mai 10; etc.<br/>
62
62
  DMY: 09.11.1518; 1 noiembrie 1624; etc.<br/>
@@ -64,15 +64,16 @@ quality and reliability of date-related information extracted from text.
64
64
  </td>
65
65
  </tr>
66
66
  <tr>
67
- <td>timespans</td>
68
- <td>
69
- centuries: s:; sc; se.; sec; sec.; secol; secolele; secolul; sex.<br/>
70
- millenniums: mil; mil.; mileniul; mileniului; mileniile
71
- </td>
67
+ <td>YEAR</td>
68
+ <td>1534; (1)931; [1833]; aproximativ 1834; cca. 1420; etc.</td>
69
+ </tr>
70
+ <tr>
71
+ <td>CENTURY</td>
72
+ <td>s: xviii; sec ii p.chr.; secol xix; secolele ii-iii; etc.</td>
72
73
  </tr>
73
74
  <tr>
74
- <td>years</td>
75
- <td>77; 78; 1652; [1873]; aproximativ 1834; cca. 1420; etc.</td>
75
+ <td>MILLENNIUM</td>
76
+ <td>mil iii; mil. 5 a.chr.; mileniul v a.chr.; a mileniului v a.chr.; etc.</td>
76
77
  </tr>
77
78
  </table>
78
79
  * The values are mentioned in the reference language – Romanian language
@@ -110,7 +111,7 @@ import spacy
110
111
  from temporal_normalization.commons.print_utils import console
111
112
 
112
113
  LANG = "ro"
113
- MODEL = "ro_core_news_sm"
114
+ MODEL = "ro_core_news_sm "
114
115
  TEXT_RO = ("Sec al II-lea a.ch. a fost o perioadă de mari schimbări. "
115
116
  "În secolul XX, tehnologia a avansat semnificativ. "
116
117
  "Sec. 21 este adesea asociat cu globalizarea rapidă.")
@@ -23,7 +23,7 @@ quality and reliability of date-related information extracted from text.
23
23
  <th>Examples of Temporal Expressions*</th>
24
24
  </tr>
25
25
  <tr>
26
- <td>dates</td>
26
+ <td>DATE</td>
27
27
  <td>
28
28
  YMD: 1881-08-31; 1857 mai 10; etc.<br/>
29
29
  DMY: 09.11.1518; 1 noiembrie 1624; etc.<br/>
@@ -31,15 +31,16 @@ quality and reliability of date-related information extracted from text.
31
31
  </td>
32
32
  </tr>
33
33
  <tr>
34
- <td>timespans</td>
35
- <td>
36
- centuries: s:; sc; se.; sec; sec.; secol; secolele; secolul; sex.<br/>
37
- millenniums: mil; mil.; mileniul; mileniului; mileniile
38
- </td>
34
+ <td>YEAR</td>
35
+ <td>1534; (1)931; [1833]; aproximativ 1834; cca. 1420; etc.</td>
36
+ </tr>
37
+ <tr>
38
+ <td>CENTURY</td>
39
+ <td>s: xviii; sec ii p.chr.; secol xix; secolele ii-iii; etc.</td>
39
40
  </tr>
40
41
  <tr>
41
- <td>years</td>
42
- <td>77; 78; 1652; [1873]; aproximativ 1834; cca. 1420; etc.</td>
42
+ <td>MILLENNIUM</td>
43
+ <td>mil iii; mil. 5 a.chr.; mileniul v a.chr.; a mileniului v a.chr.; etc.</td>
43
44
  </tr>
44
45
  </table>
45
46
  * The values are mentioned in the reference language – Romanian language
@@ -77,7 +78,7 @@ import spacy
77
78
  from temporal_normalization.commons.print_utils import console
78
79
 
79
80
  LANG = "ro"
80
- MODEL = "ro_core_news_sm"
81
+ MODEL = "ro_core_news_sm "
81
82
  TEXT_RO = ("Sec al II-lea a.ch. a fost o perioadă de mari schimbări. "
82
83
  "În secolul XX, tehnologia a avansat semnificativ. "
83
84
  "Sec. 21 este adesea asociat cu globalizarea rapidă.")
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="temporal_normalization_spacy",
5
- version="2.3.0",
5
+ version="2.4.0",
6
6
  author="Ilie Cristian Dorobat",
7
7
  author_email="ic.dorobat@gmail.com",
8
8
  description="A spaCy plugin for temporal normalization and extraction of "
@@ -19,7 +19,7 @@ setup(
19
19
  ],
20
20
  },
21
21
  package_data={
22
- "temporal_normalization.libs": ["temporal-normalization-2.2.0.jar"],
22
+ "temporal_normalization.libs": ["temporal-normalization-2.2.1.jar"],
23
23
  },
24
24
  install_requires=[
25
25
  "spacy>=3.8.7,<4.0.0",
@@ -1,9 +1,12 @@
1
1
  import io
2
+ import random
2
3
  import re
3
4
  import shutil
5
+ import socket
4
6
  import subprocess
5
7
  import threading
6
8
  import time
9
+ from pathlib import Path
7
10
 
8
11
  from py4j.java_gateway import JavaGateway, GatewayParameters
9
12
  from py4j.protocol import Py4JNetworkError
@@ -11,12 +14,17 @@ from py4j.protocol import Py4JNetworkError
11
14
  from temporal_normalization.commons.print_utils import console
12
15
 
13
16
 
14
- def start_conn(root_path: str) -> tuple[subprocess.Popen, JavaGateway]:
17
+ _DEFAULT_GATEWAY_PORT = 25333
18
+
19
+
20
+ def start_conn(root_path: str, max_attempts: int = 10, timeout: float = 10.0) -> tuple[subprocess.Popen, JavaGateway]:
15
21
  """
16
22
  Starts the Java temporal normalization process and establishes a Py4J gateway connection.
17
23
 
18
24
  Args:
19
25
  root_path (str): The root directory of the project.
26
+ max_attempts (int): Maximum number of retry attempts if port binding fails.
27
+ timeout (float): Maximum time to wait for gateway initialization (default: 10 seconds).
20
28
 
21
29
  Returns:
22
30
  tuple[subprocess.Popen, JavaGateway]:
@@ -25,22 +33,34 @@ def start_conn(root_path: str) -> tuple[subprocess.Popen, JavaGateway]:
25
33
 
26
34
  Note:
27
35
  - Requires Java 11 or higher to be installed and accessible in the system PATH.
28
- - Requires `temporal-normalization-2.2.0.jar` to be present in the `libs` directory.
36
+ - Requires `temporal-normalization-2.2.1.jar` to be present in the `libs` directory.
29
37
  - The caller is responsible for closing the gateway and terminating the Java process
30
38
  after usage to avoid orphaned processes.
39
+ - Will automatically retry with cleanup if port binding fails.
31
40
  """
32
41
 
33
42
  check_java_version()
34
43
 
35
- gateway_started = threading.Event()
36
- gateway_error = threading.Event()
37
-
38
44
  jar_path = (
39
- f"{root_path}/temporal_normalization/libs/temporal-normalization-2.2.0.jar"
45
+ # f"{root_path}/temporal_normalization/libs/temporal-normalization-1.7-patch1.jar"
46
+ f"{root_path}/temporal_normalization/libs/temporal-normalization-2.2.1.jar"
40
47
  )
41
48
 
49
+ if not Path(jar_path):
50
+ raise RuntimeError(f"JAR file not found at {jar_path}")
51
+
52
+ gateway_port = _find_available_port(max_attempts=max_attempts)
53
+ print(f"Starting Java Gateway on port {gateway_port}")
54
+
55
+ gateway_started = threading.Event()
56
+ gateway_error = threading.Event()
57
+
42
58
  def stdout_callback(line: str):
43
- if "Gateway Server Started" in line:
59
+ startup_indicators = [
60
+ "gateway server successfully started", # temporal-normalization-2.2.1.jar
61
+ "gateway server started", # temporal-normalization-1.7-patch1.jar
62
+ ]
63
+ if any(indicator in line.lower() for indicator in startup_indicators):
44
64
  gateway_started.set()
45
65
  print(line.strip())
46
66
 
@@ -52,7 +72,7 @@ def start_conn(root_path: str) -> tuple[subprocess.Popen, JavaGateway]:
52
72
  gateway_error.set()
53
73
 
54
74
  java_process = subprocess.Popen(
55
- ["java", "-jar", jar_path, "--python"],
75
+ ["java", "-jar", jar_path, "--python", f"--gateway-port={gateway_port}"],
56
76
  stdout=subprocess.PIPE,
57
77
  stderr=subprocess.PIPE,
58
78
  text=True,
@@ -61,7 +81,6 @@ def start_conn(root_path: str) -> tuple[subprocess.Popen, JavaGateway]:
61
81
  threading.Thread(target=drain_stream, args=(java_process.stdout, stdout_callback), daemon=True).start()
62
82
  threading.Thread(target=drain_stream, args=(java_process.stderr, stderr_callback), daemon=True).start()
63
83
 
64
- timeout = 10.0
65
84
  start_time = time.monotonic()
66
85
 
67
86
  while not gateway_started.is_set():
@@ -70,6 +89,7 @@ def start_conn(root_path: str) -> tuple[subprocess.Popen, JavaGateway]:
70
89
 
71
90
  if java_process.poll() is None:
72
91
  java_process.terminate()
92
+ java_process.wait(timeout=5)
73
93
 
74
94
  raise RuntimeError(
75
95
  "Java Gateway failed to start.\n"
@@ -83,18 +103,24 @@ def start_conn(root_path: str) -> tuple[subprocess.Popen, JavaGateway]:
83
103
  java_process.wait()
84
104
 
85
105
  raise RuntimeError(
86
- f"Java Gateway did not start within 10 seconds.\n"
106
+ f"Java Gateway did not start within {timeout} seconds.\n"
87
107
  f"Java stderr:\n\t{error}"
88
108
  )
89
109
 
90
110
  time.sleep(0.1)
91
111
 
92
112
  gateway = JavaGateway(
93
- gateway_parameters=GatewayParameters(auto_convert=True, read_timeout=None),
113
+ gateway_parameters=GatewayParameters(
114
+ address="127.0.0.1",
115
+ port=gateway_port,
116
+ auto_convert=True,
117
+ read_timeout=None,
118
+ eager_load=True,
119
+ ),
94
120
  callback_server_parameters=None,
95
121
  )
96
122
 
97
- print("Python connection established.")
123
+ print("✅ Python connection established.")
98
124
 
99
125
  return java_process, gateway
100
126
 
@@ -270,5 +296,51 @@ def check_java_version() -> None:
270
296
  console.error(e.__str__())
271
297
 
272
298
 
299
+ def _is_port_available(port: int) -> bool:
300
+ """
301
+ Check if a given port is available for binding.
302
+
303
+ Args:
304
+ port (int): The port number to check.
305
+
306
+ Returns:
307
+ bool: True if the port is available, False otherwise.
308
+ """
309
+ try:
310
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
311
+ s.bind(('127.0.0.1', port))
312
+ return True
313
+ except OSError:
314
+ return False
315
+
316
+
317
+ def _find_available_port(start_port: int = _DEFAULT_GATEWAY_PORT, max_attempts: int = 10) -> int:
318
+ """
319
+ Find an available port starting from the given port number.
320
+
321
+ Args:
322
+ start_port (int): The initial port to try.
323
+ max_attempts (int): Maximum number of ports to check.
324
+
325
+ Returns:
326
+ int: An available port number.
327
+
328
+ Raises:
329
+ RuntimeError: If no available port is found within max_attempts.
330
+ """
331
+ for offset in range(max_attempts):
332
+ port = start_port + offset
333
+ if _is_port_available(port):
334
+ return port
335
+
336
+ # If sequential search fails, try random ports
337
+ for _ in range(max_attempts):
338
+ port = random.randint(_DEFAULT_GATEWAY_PORT, 35333)
339
+ if _is_port_available(port):
340
+ return port
341
+
342
+ raise RuntimeError(f"Could not find an available port after {max_attempts * 2} attempts")
343
+
344
+
273
345
  if __name__ == "__main__":
274
346
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: temporal_normalization_spacy
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: A spaCy plugin for temporal normalization and extraction of historical dates in Romanian narrative texts.
5
5
  Home-page: https://github.com/iliedorobat/timespan-normalization-spacy
6
6
  Author: Ilie Cristian Dorobat
@@ -56,7 +56,7 @@ quality and reliability of date-related information extracted from text.
56
56
  <th>Examples of Temporal Expressions*</th>
57
57
  </tr>
58
58
  <tr>
59
- <td>dates</td>
59
+ <td>DATE</td>
60
60
  <td>
61
61
  YMD: 1881-08-31; 1857 mai 10; etc.<br/>
62
62
  DMY: 09.11.1518; 1 noiembrie 1624; etc.<br/>
@@ -64,15 +64,16 @@ quality and reliability of date-related information extracted from text.
64
64
  </td>
65
65
  </tr>
66
66
  <tr>
67
- <td>timespans</td>
68
- <td>
69
- centuries: s:; sc; se.; sec; sec.; secol; secolele; secolul; sex.<br/>
70
- millenniums: mil; mil.; mileniul; mileniului; mileniile
71
- </td>
67
+ <td>YEAR</td>
68
+ <td>1534; (1)931; [1833]; aproximativ 1834; cca. 1420; etc.</td>
69
+ </tr>
70
+ <tr>
71
+ <td>CENTURY</td>
72
+ <td>s: xviii; sec ii p.chr.; secol xix; secolele ii-iii; etc.</td>
72
73
  </tr>
73
74
  <tr>
74
- <td>years</td>
75
- <td>77; 78; 1652; [1873]; aproximativ 1834; cca. 1420; etc.</td>
75
+ <td>MILLENNIUM</td>
76
+ <td>mil iii; mil. 5 a.chr.; mileniul v a.chr.; a mileniului v a.chr.; etc.</td>
76
77
  </tr>
77
78
  </table>
78
79
  * The values are mentioned in the reference language – Romanian language
@@ -110,7 +111,7 @@ import spacy
110
111
  from temporal_normalization.commons.print_utils import console
111
112
 
112
113
  LANG = "ro"
113
- MODEL = "ro_core_news_sm"
114
+ MODEL = "ro_core_news_sm "
114
115
  TEXT_RO = ("Sec al II-lea a.ch. a fost o perioadă de mari schimbări. "
115
116
  "În secolul XX, tehnologia a avansat semnificativ. "
116
117
  "Sec. 21 este adesea asociat cu globalizarea rapidă.")
@@ -9,7 +9,7 @@ temporal_normalization/commons/__init__.py
9
9
  temporal_normalization/commons/print_utils.py
10
10
  temporal_normalization/commons/temporal_models.py
11
11
  temporal_normalization/commons/temporal_types.py
12
- temporal_normalization/libs/temporal-normalization-2.2.0.jar
12
+ temporal_normalization/libs/temporal-normalization-2.2.1.jar
13
13
  temporal_normalization/process/__init__.py
14
14
  temporal_normalization/process/java_process.py
15
15
  temporal_normalization_spacy.egg-info/PKG-INFO