File size: 1,610 Bytes
b4f2238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
法院文书智能识别服务适配器

实现 ICourtDocumentRecognitionService 接口,供 ServiceLocator 使用。

Requirements: 7.5
"""

from typing import Any, cast

from .data_classes import RecognitionResponse, RecognitionResult


class CourtDocumentRecognitionServiceAdapter:
    """
    法院文书智能识别服务适配器

    实现 ICourtDocumentRecognitionService 接口,
    作为 ServiceLocator 的注册入口。

    实际实现委托给 CourtDocumentRecognitionService。
    """

    def __init__(self) -> None:
        self._service = None

    @property
    def service(self) -> Any:
        """延迟加载实际服务"""
        if self._service is None:
            from .recognition_service import CourtDocumentRecognitionService

            self._service = CourtDocumentRecognitionService()  # type: ignore
        return self._service

    def recognize_document(self, file_path: str, user: Any | None = None) -> RecognitionResponse:
        """
        识别文书并绑定案件

        Args:
            file_path: 文书文件路径
            user: 当前用户

        Returns:
            RecognitionResponse 对象
        """
        return cast(RecognitionResponse, self.service.recognize_document(file_path, user))

    def recognize_document_from_text(self, text: str) -> RecognitionResult:
        """
        从已提取的文本识别文书

        Args:
            text: 文书文本内容

        Returns:
            RecognitionResult 对象
        """
        return cast(RecognitionResult, self.service.recognize_document_from_text(text))