rettxmutation 0.2.1__tar.gz → 0.2.2__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.
- {rettxmutation-0.2.1/src/rettxmutation.egg-info → rettxmutation-0.2.2}/PKG-INFO +1 -5
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/pyproject.toml +1 -5
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/__init__.py +1 -3
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/repositories/__init__.py +0 -4
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/repositories/interfaces.py +1 -27
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/__init__.py +0 -2
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/services_factory.py +7 -38
- {rettxmutation-0.2.1 → rettxmutation-0.2.2/src/rettxmutation.egg-info}/PKG-INFO +1 -5
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation.egg-info/SOURCES.txt +0 -6
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation.egg-info/requires.txt +0 -4
- rettxmutation-0.2.1/src/rettxmutation/models/document.py +0 -57
- rettxmutation-0.2.1/src/rettxmutation/repositories/document_analysis_repository.py +0 -102
- rettxmutation-0.2.1/src/rettxmutation/services/exceptions.py +0 -30
- rettxmutation-0.2.1/src/rettxmutation/services/ocr_service.py +0 -288
- rettxmutation-0.2.1/tests/test_models_document.py +0 -89
- rettxmutation-0.2.1/tests/test_ocr.py +0 -324
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/LICENSE +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/README.md +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/setup.cfg +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/config.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/models/__init__.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/models/gene_assembly.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/models/gene_models.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/models/gene_registry.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/models/keyword_collection.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/models/mutation_model.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/models/search_models.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/repositories/ai_search_repository.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/repositories/text_analytics_repository.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/repositories/variant_validator_repository.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/ai_search.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/embedding_client.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/embedding_service.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/keyword_detector_service.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/mutation_tokenizator.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/variant_validator_mapping_service.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/services/variant_validator_service.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/utils/__init__.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/utils/hgvs_descriptor.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/utils/mutation_converter.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation/utils/text_util.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation.egg-info/dependency_links.txt +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/src/rettxmutation.egg-info/top_level.txt +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/tests/test_gene_model.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/tests/test_keyword_collection.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/tests/test_keyword_detector.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/tests/test_semantic_search.py +0 -0
- {rettxmutation-0.2.1 → rettxmutation-0.2.2}/tests/test_variant_validator.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rettxmutation
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Extract Rett Syndrome mutations from genetic diagnosis report
|
|
5
5
|
Author-email: Pedro Rocha <procha@rettsyndrome.eu>
|
|
6
6
|
License: MIT License
|
|
@@ -13,15 +13,11 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: python-dotenv
|
|
16
|
-
Requires-Dist: azure-ai-formrecognizer
|
|
17
16
|
Requires-Dist: azure-core
|
|
18
17
|
Requires-Dist: azure-ai-textanalytics
|
|
19
|
-
Requires-Dist: azure.ai.documentintelligence
|
|
20
|
-
Requires-Dist: ftfy
|
|
21
18
|
Requires-Dist: mutalyzer_hgvs_parser
|
|
22
19
|
Requires-Dist: pydantic
|
|
23
20
|
Requires-Dist: openai
|
|
24
|
-
Requires-Dist: opencv-python-headless
|
|
25
21
|
Requires-Dist: backoff
|
|
26
22
|
Requires-Dist: jmespath
|
|
27
23
|
Requires-Dist: azure-search-documents
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "rettxmutation"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
authors = [
|
|
5
5
|
{ name="Pedro Rocha", email="procha@rettsyndrome.eu" },
|
|
6
6
|
]
|
|
@@ -15,15 +15,11 @@ classifiers = [
|
|
|
15
15
|
]
|
|
16
16
|
dependencies = [
|
|
17
17
|
"python-dotenv",
|
|
18
|
-
"azure-ai-formrecognizer",
|
|
19
18
|
"azure-core",
|
|
20
19
|
"azure-ai-textanalytics",
|
|
21
|
-
"azure.ai.documentintelligence",
|
|
22
|
-
"ftfy",
|
|
23
20
|
"mutalyzer_hgvs_parser",
|
|
24
21
|
"pydantic",
|
|
25
22
|
"openai",
|
|
26
|
-
"opencv-python-headless",
|
|
27
23
|
"backoff",
|
|
28
24
|
"jmespath",
|
|
29
25
|
"azure-search-documents",
|
|
@@ -29,10 +29,9 @@ from .services import (
|
|
|
29
29
|
VariantValidatorService,
|
|
30
30
|
MutationTokenizator,
|
|
31
31
|
AISearchService,
|
|
32
|
-
OcrService
|
|
33
32
|
)
|
|
34
33
|
|
|
35
|
-
__version__ = "0.2.
|
|
34
|
+
__version__ = "0.2.2"
|
|
36
35
|
|
|
37
36
|
__all__ = [
|
|
38
37
|
# Core configuration
|
|
@@ -47,7 +46,6 @@ __all__ = [
|
|
|
47
46
|
"VariantValidatorService",
|
|
48
47
|
"MutationTokenizator",
|
|
49
48
|
"AISearchService",
|
|
50
|
-
"OcrService",
|
|
51
49
|
|
|
52
50
|
# Version
|
|
53
51
|
"__version__"
|
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
from .interfaces import (
|
|
5
5
|
AISearchRepositoryInterface,
|
|
6
6
|
TextAnalyticsRepositoryInterface,
|
|
7
|
-
DocumentAnalysisRepositoryInterface,
|
|
8
7
|
VariantValidatorRepositoryInterface,
|
|
9
8
|
)
|
|
10
9
|
|
|
11
10
|
# Repository Implementations
|
|
12
|
-
from .document_analysis_repository import DocumentAnalysisRepository
|
|
13
11
|
from .text_analytics_repository import TextAnalyticsRepository
|
|
14
12
|
from .ai_search_repository import AISearchRepository
|
|
15
13
|
from .variant_validator_repository import (
|
|
@@ -22,10 +20,8 @@ __all__ = [
|
|
|
22
20
|
# Interfaces
|
|
23
21
|
"AISearchRepositoryInterface",
|
|
24
22
|
"TextAnalyticsRepositoryInterface",
|
|
25
|
-
"DocumentAnalysisRepositoryInterface",
|
|
26
23
|
"VariantValidatorRepositoryInterface",
|
|
27
24
|
# Implementations
|
|
28
|
-
"DocumentAnalysisRepository",
|
|
29
25
|
"TextAnalyticsRepository",
|
|
30
26
|
"AISearchRepository",
|
|
31
27
|
"VariantValidatorRepository",
|
|
@@ -6,8 +6,7 @@ enabling better testability and flexibility in implementation.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from abc import ABC, abstractmethod
|
|
9
|
-
from typing import Any, Dict, List,
|
|
10
|
-
from azure.ai.documentintelligence.models import AnalyzeResult, DocumentAnalysisFeature
|
|
9
|
+
from typing import Any, Dict, List, Optional
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
class AISearchRepositoryInterface(ABC):
|
|
@@ -38,31 +37,6 @@ class TextAnalyticsRepositoryInterface(ABC):
|
|
|
38
37
|
pass
|
|
39
38
|
|
|
40
39
|
|
|
41
|
-
class DocumentAnalysisRepositoryInterface(ABC):
|
|
42
|
-
"""Interface for Document Analysis repository operations."""
|
|
43
|
-
|
|
44
|
-
@abstractmethod
|
|
45
|
-
def analyze_document(
|
|
46
|
-
self,
|
|
47
|
-
file_stream: BinaryIO,
|
|
48
|
-
features: Optional[List[DocumentAnalysisFeature]] = None,
|
|
49
|
-
) -> AnalyzeResult:
|
|
50
|
-
"""
|
|
51
|
-
Analyze a document using Azure Document Analysis.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
file_stream: Binary stream of the document
|
|
55
|
-
features: Optional list of analysis features to enable
|
|
56
|
-
|
|
57
|
-
Returns:
|
|
58
|
-
AnalyzeResult: The analysis result from Azure Document Analysis
|
|
59
|
-
|
|
60
|
-
Raises:
|
|
61
|
-
Exception: If document analysis fails
|
|
62
|
-
"""
|
|
63
|
-
pass
|
|
64
|
-
|
|
65
|
-
|
|
66
40
|
class VariantValidatorRepositoryInterface(ABC):
|
|
67
41
|
"""Interface for VariantValidator repository operations."""
|
|
68
42
|
|
|
@@ -2,7 +2,6 @@ from .variant_validator_service import VariantValidatorService
|
|
|
2
2
|
from .embedding_service import EmbeddingService
|
|
3
3
|
from .mutation_tokenizator import MutationTokenizator
|
|
4
4
|
from .ai_search import AISearchService
|
|
5
|
-
from .ocr_service import OcrService
|
|
6
5
|
from .keyword_detector_service import KeywordDetectorService
|
|
7
6
|
from .services_factory import RettxServices, create_services
|
|
8
7
|
|
|
@@ -11,7 +10,6 @@ __all__ = [
|
|
|
11
10
|
"EmbeddingService",
|
|
12
11
|
"MutationTokenizator",
|
|
13
12
|
"AISearchService",
|
|
14
|
-
"OcrService",
|
|
15
13
|
"KeywordDetectorService",
|
|
16
14
|
"RettxServices",
|
|
17
15
|
"create_services"
|
|
@@ -14,10 +14,9 @@ from rettxmutation.config import RettxConfig
|
|
|
14
14
|
from rettxmutation.services.embedding_service import EmbeddingService
|
|
15
15
|
from rettxmutation.services.mutation_tokenizator import MutationTokenizator
|
|
16
16
|
from rettxmutation.services.ai_search import AISearchService
|
|
17
|
-
from rettxmutation.services.ocr_service import OcrService
|
|
18
17
|
from rettxmutation.services.keyword_detector_service import KeywordDetectorService
|
|
19
18
|
from rettxmutation.services.variant_validator_service import VariantValidatorService
|
|
20
|
-
from rettxmutation.repositories import
|
|
19
|
+
from rettxmutation.repositories import TextAnalyticsRepository
|
|
21
20
|
|
|
22
21
|
logger = logging.getLogger(__name__)
|
|
23
22
|
|
|
@@ -51,9 +50,8 @@ class RettxServices:
|
|
|
51
50
|
self._embedding_service: Optional[EmbeddingService] = None
|
|
52
51
|
self._variant_validator_service: Optional[VariantValidatorService] = None
|
|
53
52
|
self._mutation_tokenizator: Optional[MutationTokenizator] = None
|
|
54
|
-
self._ocr_service: Optional[OcrService] = None
|
|
55
53
|
self._keyword_detector_service: Optional[KeywordDetectorService] = None
|
|
56
|
-
self.
|
|
54
|
+
self._ai_search_service: Optional[AISearchService] = None
|
|
57
55
|
|
|
58
56
|
logger.debug("RettxServices factory initialized with unified configuration")
|
|
59
57
|
|
|
@@ -140,52 +138,23 @@ class RettxServices:
|
|
|
140
138
|
self._mutation_tokenizator = MutationTokenizator()
|
|
141
139
|
return self._mutation_tokenizator
|
|
142
140
|
|
|
143
|
-
@property
|
|
144
|
-
def ocr_service(self) -> OcrService:
|
|
145
|
-
"""
|
|
146
|
-
Get or create the OCR service.
|
|
147
|
-
|
|
148
|
-
Returns:
|
|
149
|
-
OcrService: Configured service for document analysis and text processing
|
|
150
|
-
|
|
151
|
-
Raises:
|
|
152
|
-
ValueError: If required configuration fields are missing
|
|
153
|
-
"""
|
|
154
|
-
if self._ocr_service is None:
|
|
155
|
-
logger.debug("Initializing OcrService with DocumentAnalysisRepository")
|
|
156
|
-
# Create the repository first
|
|
157
|
-
document_analysis_repo = DocumentAnalysisRepository(self._config)
|
|
158
|
-
# Create the service with the repository
|
|
159
|
-
self._ocr_service = OcrService(document_analysis_repo)
|
|
160
|
-
|
|
161
|
-
return self._ocr_service
|
|
162
|
-
|
|
163
141
|
@property
|
|
164
142
|
def ai_search_service(self) -> AISearchService:
|
|
165
143
|
"""Get or create the AI search service."""
|
|
166
|
-
if self.
|
|
144
|
+
if self._ai_search_service is None:
|
|
167
145
|
logger.debug("Initializing AISearchService")
|
|
168
|
-
self.
|
|
169
|
-
return self.
|
|
146
|
+
self._ai_search_service = AISearchService(self._config)
|
|
147
|
+
return self._ai_search_service
|
|
170
148
|
|
|
171
149
|
@ai_search_service.setter
|
|
172
150
|
def ai_search_service(self, service: AISearchService):
|
|
173
151
|
"""Set the AI search service (for testing purposes)."""
|
|
174
|
-
self.
|
|
152
|
+
self._ai_search_service = service
|
|
175
153
|
|
|
176
154
|
@ai_search_service.deleter
|
|
177
155
|
def ai_search_service(self):
|
|
178
156
|
"""Delete the AI search service (for testing purposes)."""
|
|
179
|
-
self.
|
|
180
|
-
@ocr_service.setter
|
|
181
|
-
def ocr_service(self, service: OcrService):
|
|
182
|
-
"""Set the OCR service (for testing purposes)."""
|
|
183
|
-
self._ocr_service = service
|
|
184
|
-
|
|
185
|
-
@ocr_service.deleter
|
|
186
|
-
def ocr_service(self):
|
|
187
|
-
"""Delete the OCR service (for testing purposes)."""
|
|
188
|
-
self._ocr_service = None
|
|
157
|
+
self._ai_search_service = None
|
|
189
158
|
|
|
190
159
|
@property
|
|
191
160
|
def keyword_detector_service(self) -> KeywordDetectorService:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rettxmutation
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Extract Rett Syndrome mutations from genetic diagnosis report
|
|
5
5
|
Author-email: Pedro Rocha <procha@rettsyndrome.eu>
|
|
6
6
|
License: MIT License
|
|
@@ -13,15 +13,11 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: python-dotenv
|
|
16
|
-
Requires-Dist: azure-ai-formrecognizer
|
|
17
16
|
Requires-Dist: azure-core
|
|
18
17
|
Requires-Dist: azure-ai-textanalytics
|
|
19
|
-
Requires-Dist: azure.ai.documentintelligence
|
|
20
|
-
Requires-Dist: ftfy
|
|
21
18
|
Requires-Dist: mutalyzer_hgvs_parser
|
|
22
19
|
Requires-Dist: pydantic
|
|
23
20
|
Requires-Dist: openai
|
|
24
|
-
Requires-Dist: opencv-python-headless
|
|
25
21
|
Requires-Dist: backoff
|
|
26
22
|
Requires-Dist: jmespath
|
|
27
23
|
Requires-Dist: azure-search-documents
|
|
@@ -9,7 +9,6 @@ src/rettxmutation.egg-info/dependency_links.txt
|
|
|
9
9
|
src/rettxmutation.egg-info/requires.txt
|
|
10
10
|
src/rettxmutation.egg-info/top_level.txt
|
|
11
11
|
src/rettxmutation/models/__init__.py
|
|
12
|
-
src/rettxmutation/models/document.py
|
|
13
12
|
src/rettxmutation/models/gene_assembly.py
|
|
14
13
|
src/rettxmutation/models/gene_models.py
|
|
15
14
|
src/rettxmutation/models/gene_registry.py
|
|
@@ -18,7 +17,6 @@ src/rettxmutation/models/mutation_model.py
|
|
|
18
17
|
src/rettxmutation/models/search_models.py
|
|
19
18
|
src/rettxmutation/repositories/__init__.py
|
|
20
19
|
src/rettxmutation/repositories/ai_search_repository.py
|
|
21
|
-
src/rettxmutation/repositories/document_analysis_repository.py
|
|
22
20
|
src/rettxmutation/repositories/interfaces.py
|
|
23
21
|
src/rettxmutation/repositories/text_analytics_repository.py
|
|
24
22
|
src/rettxmutation/repositories/variant_validator_repository.py
|
|
@@ -26,10 +24,8 @@ src/rettxmutation/services/__init__.py
|
|
|
26
24
|
src/rettxmutation/services/ai_search.py
|
|
27
25
|
src/rettxmutation/services/embedding_client.py
|
|
28
26
|
src/rettxmutation/services/embedding_service.py
|
|
29
|
-
src/rettxmutation/services/exceptions.py
|
|
30
27
|
src/rettxmutation/services/keyword_detector_service.py
|
|
31
28
|
src/rettxmutation/services/mutation_tokenizator.py
|
|
32
|
-
src/rettxmutation/services/ocr_service.py
|
|
33
29
|
src/rettxmutation/services/services_factory.py
|
|
34
30
|
src/rettxmutation/services/variant_validator_mapping_service.py
|
|
35
31
|
src/rettxmutation/services/variant_validator_service.py
|
|
@@ -40,7 +36,5 @@ src/rettxmutation/utils/text_util.py
|
|
|
40
36
|
tests/test_gene_model.py
|
|
41
37
|
tests/test_keyword_collection.py
|
|
42
38
|
tests/test_keyword_detector.py
|
|
43
|
-
tests/test_models_document.py
|
|
44
|
-
tests/test_ocr.py
|
|
45
39
|
tests/test_semantic_search.py
|
|
46
40
|
tests/test_variant_validator.py
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
from typing import Optional, List
|
|
3
|
-
from pydantic import BaseModel, Field
|
|
4
|
-
|
|
5
|
-
logger = logging.getLogger(__name__)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# Word data model, extracted from a document by OCR tool
|
|
9
|
-
class WordData(BaseModel):
|
|
10
|
-
word: str = Field(..., description="The word extracted from the document")
|
|
11
|
-
confidence: float = Field(..., description="Confidence score of the extracted word")
|
|
12
|
-
page_number: int = Field(..., description="Page number where the word was found")
|
|
13
|
-
offset: int = Field(None, description="Offset of the word in the page")
|
|
14
|
-
length: int = Field(None, description="Length of the word")
|
|
15
|
-
|
|
16
|
-
# Line data model, extracted from a document by OCR tool
|
|
17
|
-
class LineData(BaseModel):
|
|
18
|
-
line: str = Field(..., description="The line extracted from the document")
|
|
19
|
-
page_number: int = Field(..., description="Page number where the line was found")
|
|
20
|
-
length: int = Field(None, description="Length of the line")
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# Document model
|
|
24
|
-
class Document(BaseModel):
|
|
25
|
-
raw_text: str = Field(..., description="The extracted text from the document")
|
|
26
|
-
cleaned_text: Optional[str] = Field("", description="The cleaned version of the extracted text")
|
|
27
|
-
summary: Optional[str] = Field("", description="Summary of the document content")
|
|
28
|
-
language: str = Field(..., description="Language of the extracted text")
|
|
29
|
-
words: List[WordData] = Field(..., description="List of extracted words with confidence scores")
|
|
30
|
-
lines: List[LineData] = Field(..., description="List of extracted lines")
|
|
31
|
-
|
|
32
|
-
def find_word_confidence(self, word_to_find: str) -> Optional[float]:
|
|
33
|
-
"""
|
|
34
|
-
Finds a word in the word data and returns its confidence value.
|
|
35
|
-
|
|
36
|
-
:param word_to_find: The word to search for in the words data.
|
|
37
|
-
:return: The confidence score of the word if found, else None.
|
|
38
|
-
"""
|
|
39
|
-
for word_data in self.words:
|
|
40
|
-
if word_to_find in word_data.word:
|
|
41
|
-
return word_data.confidence
|
|
42
|
-
return None
|
|
43
|
-
|
|
44
|
-
def dump_all_content(self) -> dict:
|
|
45
|
-
"""
|
|
46
|
-
Dump the document content into a dictionary for serialization.
|
|
47
|
-
"""
|
|
48
|
-
return {
|
|
49
|
-
"cleaned_text": self.cleaned_text,
|
|
50
|
-
"language": self.language
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
def dump_plain_text(self) -> str:
|
|
54
|
-
"""
|
|
55
|
-
Generates a plain text output from cleaned_text.
|
|
56
|
-
"""
|
|
57
|
-
return self.cleaned_text.strip()
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Document Analysis Repository
|
|
3
|
-
|
|
4
|
-
Repository implementation for Azure Document Intelligence operations.
|
|
5
|
-
This handles the infrastructure concerns of interacting with Azure Document Analysis.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import logging
|
|
9
|
-
from typing import BinaryIO, Optional, List
|
|
10
|
-
from azure.core.credentials import AzureKeyCredential
|
|
11
|
-
from azure.ai.formrecognizer import DocumentAnalysisClient
|
|
12
|
-
from azure.ai.documentintelligence.models import DocumentAnalysisFeature, AnalyzeResult
|
|
13
|
-
|
|
14
|
-
from rettxmutation.config import RettxConfig, validate_config_fields
|
|
15
|
-
from rettxmutation.repositories.interfaces import DocumentAnalysisRepositoryInterface
|
|
16
|
-
|
|
17
|
-
logger = logging.getLogger(__name__)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class DocumentAnalysisRepository(DocumentAnalysisRepositoryInterface):
|
|
21
|
-
"""
|
|
22
|
-
Repository for Azure Document Analysis operations.
|
|
23
|
-
|
|
24
|
-
This class handles the infrastructure concerns of interacting with
|
|
25
|
-
Azure Document Intelligence / Form Recognizer API.
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
def __init__(self, config: RettxConfig):
|
|
29
|
-
"""
|
|
30
|
-
Initialize the Document Analysis repository with configuration.
|
|
31
|
-
|
|
32
|
-
Args:
|
|
33
|
-
config: Configuration object implementing RettxConfig protocol
|
|
34
|
-
|
|
35
|
-
Raises:
|
|
36
|
-
ValueError: If required configuration fields are missing or invalid
|
|
37
|
-
"""
|
|
38
|
-
# Validate required configuration fields for this repository
|
|
39
|
-
required_fields = [
|
|
40
|
-
'RETTX_DOCUMENT_ANALYSIS_ENDPOINT',
|
|
41
|
-
'RETTX_DOCUMENT_ANALYSIS_KEY'
|
|
42
|
-
]
|
|
43
|
-
validate_config_fields(config, required_fields, 'DocumentAnalysisRepository')
|
|
44
|
-
|
|
45
|
-
# Store config for internal use
|
|
46
|
-
self._config = config
|
|
47
|
-
|
|
48
|
-
# Initialize the Document Analysis client with validated configuration
|
|
49
|
-
try:
|
|
50
|
-
self._client = DocumentAnalysisClient(
|
|
51
|
-
endpoint=config.RETTX_DOCUMENT_ANALYSIS_ENDPOINT,
|
|
52
|
-
credential=AzureKeyCredential(config.RETTX_DOCUMENT_ANALYSIS_KEY)
|
|
53
|
-
)
|
|
54
|
-
logger.debug("DocumentAnalysisRepository initialized successfully")
|
|
55
|
-
except Exception as e:
|
|
56
|
-
logger.error(f"Failed to initialize DocumentAnalysisClient: {e}")
|
|
57
|
-
raise ValueError(f"DocumentAnalysisRepository initialization failed: {e}") from e
|
|
58
|
-
|
|
59
|
-
def analyze_document(
|
|
60
|
-
self,
|
|
61
|
-
file_stream: BinaryIO,
|
|
62
|
-
features: Optional[List[DocumentAnalysisFeature]] = None,
|
|
63
|
-
) -> AnalyzeResult:
|
|
64
|
-
"""
|
|
65
|
-
Analyze a document using Azure Document Analysis.
|
|
66
|
-
|
|
67
|
-
Args:
|
|
68
|
-
file_stream: Binary stream of the document
|
|
69
|
-
features: Optional list of analysis features to enable
|
|
70
|
-
|
|
71
|
-
Returns:
|
|
72
|
-
AnalyzeResult: The analysis result from Azure Document Analysis
|
|
73
|
-
|
|
74
|
-
Raises:
|
|
75
|
-
Exception: If document analysis fails
|
|
76
|
-
"""
|
|
77
|
-
try:
|
|
78
|
-
logger.debug("Analyzing document with Azure Document Analysis")
|
|
79
|
-
|
|
80
|
-
# Use default features if none provided
|
|
81
|
-
if features is None:
|
|
82
|
-
features = [DocumentAnalysisFeature.LANGUAGES]
|
|
83
|
-
|
|
84
|
-
poller = self._client.begin_analyze_document(
|
|
85
|
-
"prebuilt-read",
|
|
86
|
-
document=file_stream,
|
|
87
|
-
features=features
|
|
88
|
-
)
|
|
89
|
-
result: AnalyzeResult = poller.result()
|
|
90
|
-
|
|
91
|
-
if not result:
|
|
92
|
-
error_msg = "No valid document found by Azure Document Analysis"
|
|
93
|
-
logger.error(error_msg)
|
|
94
|
-
raise Exception(error_msg)
|
|
95
|
-
|
|
96
|
-
logger.debug(f"Document analysis completed: {len(result.pages)} pages processed")
|
|
97
|
-
return result
|
|
98
|
-
|
|
99
|
-
except Exception as e:
|
|
100
|
-
error_msg = f"Error analyzing document: {e}"
|
|
101
|
-
logger.error(error_msg)
|
|
102
|
-
raise Exception(error_msg) from e
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Service Layer Exceptions
|
|
3
|
-
|
|
4
|
-
Custom exceptions for the services layer of RettXMutation library.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class ServiceException(Exception):
|
|
9
|
-
"""Base exception for service-related errors."""
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class OcrException(ServiceException):
|
|
14
|
-
"""Base exception for OCR-related errors."""
|
|
15
|
-
pass
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class OcrExtractionError(OcrException):
|
|
19
|
-
"""Raised when OCR text extraction fails."""
|
|
20
|
-
pass
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class OcrProcessingError(OcrException):
|
|
24
|
-
"""Raised when OCR text processing (cleaning, variant detection) fails."""
|
|
25
|
-
pass
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class OcrConfidenceError(OcrException):
|
|
29
|
-
"""Raised when OCR confidence validation fails."""
|
|
30
|
-
pass
|