中文简繁体转换器
更新时间:2026-04-23
简介
基于OpenCC的中文简繁体转换器
功能描述
- 多方向转换:支持简繁体、台湾正体、香港繁体等多种转换方向
- 混合文本处理:正确处理中英文混杂内容,仅转换中文部分
- 高效批处理:支持大批量文本的快速转换处理
算子参数
输入
| 输入 | 含义 |
|---|---|
| texts | 包含待转换文本的列,元素类型为字符串。 |
输出
| 输出 | 含义 |
|---|---|
| converted_text | 转换后的文本列,元素类型为字符串。 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| direction | str | t2s | 转换方向 可选值:["t2s", "s2t", "t2tw", "s2tw", "t2hk", "s2hk", "tw2s", "hk2s"] 默认值:"t2s" (繁体转简体) |
调用示例
Plain Text
1from __future__ import annotations
2
3import os
4import daft
5import pandas as pd
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.text.chinese_text_converter import ChineseTextConverter
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18 samples = {
19 "text": [
20 "這是一段純繁體中文測試句子,歡迎使用軟體開發工具。",
21 "使用 Python 進行資料處理,pip install 安裝套件非常方便。",
22 "这是简体,這是繁體,and this is English,三种文字混合测试。",
23 None,
24 ]
25 }
26
27 df = pd.DataFrame(samples)
28 ds = daft.from_pandas(df)
29
30 ds = ds.with_column(
31 "converted_text",
32 aihc_udf(
33 ChineseTextConverter,
34 construct_args={
35 "direction": "t2s",
36 },
37 num_gpus=0,
38 num_cpus=1,
39 batch_size=1,
40 concurrency=1,
41 )(col("text")),
42 )
43
44 ds.show()
评价此篇文章
