55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Any
|
|
|
|
|
|
@dataclass
|
|
class Block:
|
|
id: str
|
|
page: int
|
|
type: str
|
|
text: str
|
|
bbox: tuple[float, float, float, float]
|
|
meta: dict[str, Any] = field(default_factory=dict)
|
|
|
|
def cx(self) -> float:
|
|
return (self.bbox[0] + self.bbox[2]) / 2.0
|
|
|
|
def cy(self) -> float:
|
|
return (self.bbox[1] + self.bbox[3]) / 2.0
|
|
|
|
|
|
@dataclass
|
|
class Chunk:
|
|
id: str
|
|
heading_path: str
|
|
text: str
|
|
index: int
|
|
source: str
|
|
|
|
|
|
@dataclass
|
|
class Context:
|
|
file_type: str = ""
|
|
pages: int = 0
|
|
images: int = 0
|
|
ocr_characters: int = 0
|
|
flows_detected: int = 0
|
|
warnings: list[str] = field(default_factory=list)
|
|
confidence: float = 1.0
|
|
extras: dict[str, Any] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass
|
|
class DocumentProfile:
|
|
file_type: str
|
|
text_density: float
|
|
has_images: bool
|
|
has_tables: bool
|
|
flow_likelihood: float
|
|
scan_likelihood: float
|
|
table_likelihood: float
|
|
language_hint: str
|
|
recommended_pipeline: list[str]
|