From ccdbbfbbc0955d7ba9b843347fdec2bb2b0f1863 Mon Sep 17 00:00:00 2001 From: Ben King Date: Thu, 4 Sep 2025 12:37:01 -0400 Subject: [PATCH 1/2] Detect quote convention from file Paratext project --- ...atext_project_quote_convention_detector.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 machine/corpora/file_paratext_project_quote_convention_detector.py diff --git a/machine/corpora/file_paratext_project_quote_convention_detector.py b/machine/corpora/file_paratext_project_quote_convention_detector.py new file mode 100644 index 00000000..ef625ab2 --- /dev/null +++ b/machine/corpora/file_paratext_project_quote_convention_detector.py @@ -0,0 +1,19 @@ +from pathlib import Path +from typing import BinaryIO, Optional + +from ..utils.typeshed import StrPath +from .file_paratext_project_settings_parser import FileParatextProjectSettingsParser +from .paratext_project_quote_convention_detector import ParatextProjectQuoteConventionDetector + + +class FileParatextProjectQuoteConventionDetector(ParatextProjectQuoteConventionDetector): + def __init__(self, project_dir: StrPath) -> None: + super().__init__(FileParatextProjectSettingsParser(project_dir)) + + self._project_dir = project_dir + + def _exists(self, file_name: str) -> bool: + return (Path(self._project_dir) / file_name).exists() + + def _open(self, file_name: str) -> Optional[BinaryIO]: + return open(Path(self._project_dir) / file_name, mode="rb") From 20f78970686d8a961249fc3206bef470f8264727 Mon Sep 17 00:00:00 2001 From: Ben King Date: Mon, 8 Sep 2025 09:51:11 -0400 Subject: [PATCH 2/2] Address reviewer comments --- .../file_paratext_project_quote_convention_detector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/machine/corpora/file_paratext_project_quote_convention_detector.py b/machine/corpora/file_paratext_project_quote_convention_detector.py index ef625ab2..36d3db80 100644 --- a/machine/corpora/file_paratext_project_quote_convention_detector.py +++ b/machine/corpora/file_paratext_project_quote_convention_detector.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import BinaryIO, Optional +from typing import BinaryIO from ..utils.typeshed import StrPath from .file_paratext_project_settings_parser import FileParatextProjectSettingsParser @@ -15,5 +15,5 @@ def __init__(self, project_dir: StrPath) -> None: def _exists(self, file_name: str) -> bool: return (Path(self._project_dir) / file_name).exists() - def _open(self, file_name: str) -> Optional[BinaryIO]: + def _open(self, file_name: StrPath) -> BinaryIO: return open(Path(self._project_dir) / file_name, mode="rb")