> ## Documentation Index
> Fetch the complete documentation index at: https://ladygraph.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# translation

> Dịch có căn chỉnh, nâng cấp, xác minh và gợi ý thuật ngữ.

Dịch một đoạn văn sao cho những gì tìm thấy trong bản dịch vẫn có thể được trỏ tới trong bản gốc.

## `translation.aligned`

Dịch có căn chỉnh: ánh xạ giữa một khoảng nguồn và bản dịch của nó là chính xác vì các điểm cắt là của chúng ta.

#### `Aligned`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `segments` | `list[Segment]` | required |
| `translations` | `list[str]` | required |
| `first_try_ok` | `bool` | required |
| `refilled` | `int` | required |
| `numbers_ok` | `list[bool]` | factory |

#### `AlignedConfig`

Cách diễn đạt của hai prompt.

| Trường | Kiểu | Mặc định |
| - | - | - |
| `source_language` | `str` | `'the source language'` |
| `target_language` | `str` | `'English'` |
| `domain` | `str` | `'text'` |
| `keep` | `str` | `'Keep numbers, percentages, acronyms and formulas exactly; keep proper names as written.'` |

| Phương thức | Làm gì |
| - | - |
| `numbered(self, lines: str) -> str` | — |
| `single(self, text: str) -> str` | — |

#### `AlignedTranslator`

`ask(prompt) -> reply text`: bất kỳ mô hình nào, cục bộ hay từ xa.

Khởi tạo bằng `AlignedTranslator(ask: Callable[[str], str], config: AlignedConfig \| None = None)`.

| Phương thức | Làm gì |
| - | - |
| `translate(self, raw: str, hint: str = '') -> Aligned` | — |

#### `Segment`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `start` | `int` | required |
| `length` | `int` | required |
| `text` | `str` | required |

#### `numbers_match`

```python theme={null}
numbers_match(source: str, translation: str) -> bool
```

Cùng các con số, xét như một đa tập hợp: một chữ số bị bỏ hoặc bị đổi là lỗi quan trọng nhất trong một quy tắc.

#### `parse_numbered`

```python theme={null}
parse_numbered(reply: str, n: int) -> dict[int, str]
```

\{number: text} cho các dòng của `reply` có dạng `[k] text` với 1 \<= k \<= n.

#### `segments`

```python theme={null}
segments(raw: str) -> tuple[str, list[Segment]]
```

(đoạn văn dạng faithful, mỗi dòng không rỗng một Segment).

## `translation.checks`

Các kiểm tra trên một bản dịch, dưới dạng một hàm `check(source, translation) -> [problems]`; danh sách rỗng nghĩa là đã đạt.

#### `basic`

```python theme={null}
basic(source: str, translation: str) -> list[str]
```

Câu trả lời rỗng, hoặc các con số khác với nguồn.

#### `make_check`

```python theme={null}
make_check(glossary=None, extra: Sequence[Callable[[str, str], list[str]]] = ()) -> Callable[[str, str], list[str]]
```

`basic`, cộng cổng danh sách thuật ngữ của `ladygraph.llm.translate` khi có một Glossary, cộng bất kỳ kiểm tra nào của riêng bạn.

## `translation.escalation`

Nâng cấp: một bước rẻ trước; các bước mạnh hơn chỉ cho những gì phép kiểm tra từ chối.

#### `Attempt`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `step` | `str` | required |
| `text` | `str` | required |
| `problems` | `list[str]` | required |

#### `Outcome`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `text` | `str` | required |
| `problems` | `list[str]` | required |
| `route` | `Literal['first', 'escalated', 'first_kept']` | required |
| `attempts` | `list[Attempt]` | factory |

| Phương thức | Làm gì |
| - | - |
| `(property)` | — |

#### `Step`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `name` | `str` | required |
| `run` | `Callable[[str, str], str]` | required |
| `before` | `Callable[[str, list[str]], str] \| None` | `None` |

#### `escalate`

```python theme={null}
escalate(source: str, steps: list[Step], check: Callable[[str, str], list[str]], hint: str = '') -> Outcome
```

## `translation.hints`

Gợi ý thuật ngữ: các mục bảng thuật ngữ xuất hiện trong một văn bản, dưới dạng một ghi chú nối vào prompt dịch.

#### `term_hint`

```python theme={null}
term_hint(text: str, glossary, *, statuses: tuple[str, ...] = ('approved', 'proposed'), header: str = 'Glossary (use these renderings)') -> str
```

"\n\nGlossary (...): term = rendering; ..." cho các thuật ngữ của `glossary` tìm thấy trong `text`, từ dài nhất trước, hoặc "" khi không có thuật ngữ nào.

## `translation.verify`

Xác minh: một mô hình thứ hai đọc các cặp (nguồn, bản dịch) và báo cái gì sai, theo một bộ từ vựng cố định về các kiểu lỗi.

#### `LlmVerifier`

Khởi tạo bằng `LlmVerifier(llm: LlmClient, *, source_language: str = 'the source language', target_language: str = 'English', domain: str = 'text', batch: int = 8)`.

| Phương thức | Làm gì |
| - | - |
| `verify(self, pairs: Sequence[tuple[str, str, str]]) -> list[Verdict]` | — |

#### `Verdict`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `id` | `str` | required |
| `verdict` | `Literal['ok', 'minor', 'major', 'unchecked']` | required |
| `errors` | `list[VerdictError]` | `[]` |
| `note` | `str` | `''` |

#### `VerdictError`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `type` | `Literal['untranslated', 'name_mistranslated', 'wrong_term', 'number_dropped_or_changed', 'meaning_changed', 'added_text', 'missing_text']` | required |
| `source` | `str` | `''` |
| `translation` | `str` | `''` |
| `correct` | `str` | `''` |

#### `Verifier`

Khởi tạo bằng `Verifier(*args, **kwargs)`.

| Phương thức | Làm gì |
| - | - |
| `verify(self, pairs: Sequence[tuple[str, str, str]]) -> list[Verdict]` | `pairs` là (id, nguồn, bản dịch). |

#### `verifier_check`

```python theme={null}
verifier_check(verifier: Verifier, fail_on: tuple[str, ...] = ('major',))
```

Một phép kiểm tra nâng cấp (`check(source, translation) -> problems`) dựa trên một bộ xác minh: một phán quyết nằm trong `fail_on` trở thành các vấn đề.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.