产品文档
蒙文文字转换
更新于 2026-12-03
传统蒙古文(回鹘式)与西里尔蒙古文双向高精度转换,支持拼写风格与逐词置信度标注。
能力与用法
蒙文文字转换提供传统蒙古文(回鹘式,标准 Unicode)与西里尔蒙古文(蒙古国通用)之间的高精度双向转换,按行处理并原样保留空行与段落结构,适用于新闻出版双文同步、OCR 识别后转写、跨地区语料互转与教学辅助。
通过 direction 指定方向(t2c 传统转西里尔 / c2t 西里尔转传统);在 c2t 方向下可通过 style 选择内蒙古写法(NM,后缀前用窄空格 U+202F)或蒙古国写法(MN,后缀前用元音分隔符 U+180E);开启 scores=true 可额外返回逐行平均对数概率(logprob)与不确定词标注(uncertain),便于人工复核或编辑器高亮。
端点列表
| 方法 | 路径 | 说明 |
|---|---|---|
| POST | /v1/script/convert | 传统蒙古文 ↔ 西里尔蒙古文双向文字转换(application/json,单次上限 200,000 字符,返回 HTTP 200) |
完整参数、响应示例与多语言代码见本页下方「API 参考」。
参数与规格
请求参数(POST /v1/script/convert)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
text | string | 必填 | 待转换蒙古文文本,长度 1 至 200,000 字符(不可为纯空白字符串);按行处理并保留空行。传统蒙古文输入须为标准 Unicode 编码;空串、纯空白或超过 200,000 字符返回 400 invalid_request。 |
direction | string | 可选 | 转换方向:t2c 传统蒙古文 → 西里尔蒙古文;c2t 西里尔蒙古文 → 传统蒙古文;非法取值返回 400 invalid_request。 |
style | string | 可选 | 传统蒙古文拼写规范(仅 direction=c2t 生效):NM 内蒙古写法(格后缀前使用 U+202F);MN 蒙古国写法(格后缀前使用 U+180E)。direction=t2c 时忽略并在响应中返回 null。 |
scores | boolean | 可选 | 设为 true 时响应额外返回 lines 数组,包含逐行平均对数概率与不确定词列表。 |
响应字段(200 OK)
| 字段 | 类型 | 说明 |
|---|---|---|
object | string | 对象类型标识,固定为 convert.result |
direction | string | 本次生效的转换方向 |
style | string | null | direction=c2t 时返回生效拼写风格;direction=t2c 时固定为 null |
text | string | 转换后的完整文本(保留输入换行与空行) |
usage | object | 本次调用计费统计 |
└chars | integer | 本次实际计费的有效字符数(不含空白、换行与蒙古文格式控制符) |
timing | object | 服务端处理耗时信息 |
└totalMs | integer | 服务端总处理耗时(毫秒) |
lines | object[] | 仅当 scores=true 时返回,与输入逐行一一对应 |
└source | string | 该行原文 |
└text | string | 该行转换结果 |
└logprob | number | 该行平均对数概率(数值越接近 0 把握越高) |
└uncertain | object[] | 不确定词与未登录词标注列表 |
└word | string | 触发标注的词文本 |
└reason | string | 标注原因:lowprob 对数概率偏低;oov 未登录词;lowprob+oov 同时命中。 |
典型用法示例
cURL:西里尔蒙古文转传统蒙古文(含 scores 校对标注)
指定 direction=c2t、style=NM 并开启 scores=true 获取逐行置信度与不确定词。
curl -sS -X POST "https://cloud.heimori.cn/v1/script/convert" \
-H "Authorization: Bearer ${XM_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"text": "Монгол хэл бичиг\nХэймори платформ",
"direction": "c2t",
"style": "NM",
"scores": true
}'响应示例:
{
"object": "convert.result",
"direction": "c2t",
"style": "NM",
"text": "ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ ᠪᠢᠴᠢᠭ\nᠾᠧᠢᠮᠣᠷᠢ ᠫᠯᠠᠲ᠋ᠹᠣᠷᠮ",
"usage": {
"chars": 29
},
"timing": {
"totalMs": 62
},
"lines": [
{
"source": "Монгол хэл бичиг",
"text": "ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ ᠪᠢᠴᠢᠭ",
"logprob": -0.042,
"uncertain": []
},
{
"source": "Хэймори платформ",
"text": "ᠾᠧᠢᠮᠣᠷᠢ ᠫᠯᠠᠲ᠋ᠹᠣᠷᠮ",
"logprob": -0.318,
"uncertain": [
{
"word": "Хэймори",
"reason": "oov"
}
]
}
]
}cURL:传统蒙古文转西里尔蒙古文(默认 t2c)
direction 默认为 t2c,此时响应中的 style 固定为 null。
curl -sS -X POST "https://cloud.heimori.cn/v1/script/convert" \
-H "Authorization: Bearer ${XM_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"text": "ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ ᠪᠢᠴᠢᠭ",
"direction": "t2c"
}'响应示例:
{
"object": "convert.result",
"direction": "t2c",
"style": null,
"text": "Монгол хэл бичиг",
"usage": {
"chars": 14
},
"timing": {
"totalMs": 48
}
}Python:双向文字转换与 Retry-After 退避重试(requests)
封装转换请求,自动处理 429 限流的 Retry-After 响应头,并提取需要人工复核的行。
import os
import time
import requests
API_URL = "https://cloud.heimori.cn/v1/script/convert"
HEADERS = {
"Authorization": f"Bearer {os.environ['XM_API_KEY']}",
"Content-Type": "application/json",
}
def convert_script(text: str, direction: str = "t2c", style: str = "NM", scores: bool = False) -> dict:
payload = {"text": text, "direction": direction, "style": style, "scores": scores}
for attempt in range(3):
resp = requests.post(API_URL, headers=HEADERS, json=payload, timeout=60)
if resp.status_code in (429, 502) and attempt < 2:
wait = int(resp.headers.get("Retry-After", 2 ** (attempt + 1)))
time.sleep(wait)
continue
if not resp.ok:
raise RuntimeError(f"HTTP {resp.status_code} requestId={resp.headers.get('X-Request-Id')} body={resp.text}")
return resp.json()
raise RuntimeError("重试次数已耗尽")
if __name__ == "__main__":
res = convert_script("Монгол хэл бичиг", direction="c2t", style="NM", scores=True)
print("转换结果:", res["text"])
print("计费有效字符:", res["usage"]["chars"], "耗时(ms):", res["timing"]["totalMs"])
for line in res.get("lines", []):
if line["uncertain"]:
print("待校对行:", line["source"], "->", line["uncertain"])Node.js:双向文字转换(原生 fetch)
Node.js 18+ 示例:分别演示 c2t(带 scores)与 t2c 调用。
async function convertScript({ text, direction = "t2c", style = "NM", scores = false }) {
const resp = await fetch("https://cloud.heimori.cn/v1/script/convert", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.XM_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ text, direction, style, scores }),
});
if (!resp.ok) {
throw new Error(`HTTP ${resp.status} requestId=${resp.headers.get("x-request-id")} ${await resp.text()}`);
}
return resp.json();
}
const c2t = await convertScript({
text: "Монгол хэл бичиг",
direction: "c2t",
style: "MN",
scores: true,
});
console.log("c2t(MN):", c2t.text, "chars:", c2t.usage.chars);
const t2c = await convertScript({
text: "ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ ᠪᠢᠴᠢᠭ",
direction: "t2c",
});
console.log("t2c:", t2c.text, "style:", t2c.style);计费口径、响应头与编码前置
计费与调用规则
| 项目 | 规则与说明 |
|---|---|
| 计费口径 | 按输入文本中的有效字符数计费(不含空白、换行及蒙古文格式控制符,以响应 usage.chars 为准);余额预检按输入去首尾空白后的字符数估算 |
| 传统蒙文编码前置 | 传统蒙古文输入须使用标准 Unicode 编码;若历史语料为蒙科立私有编码,请先调用「蒙古文编码转换」(to="standard")清洗后再送转 |
| 结构保留 | 按换行符逐行处理并保留空行,适合整篇文章、双语对照表或字幕文本批量转写 |
| 响应头 | 正常返回 X-Request-Id、X-RateLimit-Remaining、X-RateLimit-Reset;限流(429)或算力暂不可用(502)时返回 Retry-After(建议等待秒数) |
常见错误码
| HTTP | error.code | 触发场景与处理建议 |
|---|---|---|
400 | invalid_request | text 为空、全空白字符串或超过 200,000 字符上限(大文本请按换行边界分段提交);direction、style 或 scores 类型与取值不合法 |
401 | invalid_api_key | 缺少或无效的 Authorization: Bearer 密钥 |
402 | insufficient_balance | 账户余额不足,请前往费用中心充值 |
403 | scope_not_allowed | 当前 API Key 未开通 script-convert 权限或来源 IP 不在白名单内 |
429 | rate_limitedconcurrency_limiteddaily_quota_exceeded | 触发限流,请按响应头 Retry-After 等待后重试 |
502 | upstream_error | 文字转换服务暂时不可用,请按 Retry-After 或指数退避重试(不计费) |
支持语种
- 在传统蒙古文(回鹘式,标准 Unicode)与西里尔蒙古文(蒙古国通用)之间双向转换。
- 传统蒙古文输入请使用标准 Unicode 编码;按行处理并保留空行,单次上限 20 万字符。
转换方向(参数 direction):
| 代码 | 语种 | 说明 |
|---|---|---|
t2c | 传统蒙古文 → 西里尔蒙古文 | 默认值 |
c2t | 西里尔蒙古文 → 传统蒙古文 | — |
传统蒙古文拼写规范(仅 direction=c2t 生效)(参数 style):
| 代码 | 语种 | 说明 |
|---|---|---|
NM | 内蒙古写法 | 默认值;格后缀前使用窄空格 U+202F |
MN | 蒙古国写法 | 格后缀前使用元音分隔符 U+180E |
完整代码表与各产品对照见「语种与语言代码」。
计费
- 计费单位:字符
- 完成个人实名认证后启用每月免费额度,月初重置、优先于余额抵扣;未实名账户需充值余额后按量计费。
- 仅对成功调用计费,失败调用不扣费。
- 单价与每月免费额度见本页下方「当前价格」,总规则见计费与免费额度。
当前价格
| 计费单位 | 单价 | 每月免费额度 |
|---|---|---|
| 按字符计费 | ¥0.05 / 千字符 | 2 万 字符 / 月 |
每月免费额度需完成个人实名认证后启用;未实名账户充值余额后按上方单价计费。
API 参考
本产品共 1 个接口,全部接口见API 参考索引。
传统蒙古文 ↔ 西里尔蒙古文转换
/v1/script/convert在传统蒙古文(回鹘式,标准 Unicode)与西里尔蒙古文(蒙古国通用)之间进行高精度双向文字转换。
direction=t2c(默认):传统蒙古文 → 西里尔蒙古文;direction=c2t:西里尔蒙古文 → 传统蒙古文,可通过style选择NM(内蒙古写法,后缀前用 U+202F)或MN(蒙古国写法,后缀前用 U+180E);scores=true:额外返回逐行对数概率与不确定词标注(lines),适合人工校对与编辑器高亮。
按输入文本中的有效字符数计费(不含空白、换行与蒙古文格式控制符),单次上限 20 万字符。
请求参数application/json
| 参数 | 类型 | 说明 |
|---|---|---|
text必填 | string | 待转换的蒙古文文本(按行处理、保留空行),单次不超过 200000 字符。 示例: ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ ᠪᠢᠴᠢᠭ |
direction可选 | string | 转换方向:`t2c` 传统蒙古文 → 西里尔蒙古文(默认);`c2t` 西里尔蒙古文 → 传统蒙古文。 可选值: t2c默认c2t示例: t2c |
style可选 | string | 传统蒙古文拼写规范(仅 `direction=c2t` 生效):`NM` 内蒙古写法(默认,后缀前使用 U+202F);`MN` 蒙古国写法(后缀前使用 U+180E)。 可选值: NM默认MN示例: NM |
scores可选 | boolean | 是否返回逐行置信度与不确定词标注(`lines` 字段),适合人工复核或编辑器高亮;默认 `false`。 默认值: false示例: false |
响应
HTTP 200application/json转换成功响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
object | string | 对象类型标识,固定为 convert.result 可选值: convert.result示例: convert.result |
direction | string | 实际执行的转换方向 可选值: t2cc2t示例: t2c |
style | string | null | direction=c2t 时为生效的拼写风格(NM 或 MN);direction=t2c 时为 null 可选值: NMMN示例: null |
text | string | 转换后的完整文本 示例: Монгол хэл бичиг |
usage | object | 本次调用计费字符统计 |
└ chars | number | 计费字符数(按输入文本中不含空白与蒙古文格式控制符的字符统计) 示例: 14 |
timing | object | 服务端处理耗时 |
└ totalMs | number | 服务端处理耗时(毫秒) 示例: 85 |
lines | array<object> | 仅 scores=true 时返回:逐行转换结果与不确定词标注 |
└ source | string | 该行原文 示例: ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ |
└ text | string | 该行转换结果 示例: Монгол хэл |
└ logprob | number | 该行平均对数概率 示例: -0.042 |
└ uncertain | array<object> | 不确定词与未登录词标注列表 示例: [] |
└ word | string | 触发标注的词文本 示例: ᠥᠪᠥᠷ |
└ reason | string | 标注原因:lowprob 对数概率偏低;oov 未登录词;lowprob+oov 同时命中 可选值: lowproboovlowprob+oov示例: lowprob |
响应示例
{
"object": "convert.result",
"direction": "t2c",
"style": null,
"text": "Монгол хэл бичиг",
"usage": {
"chars": 14
},
"timing": {
"totalMs": 85
},
"lines": [
{
"source": "ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ",
"text": "Монгол хэл",
"logprob": -0.042,
"uncertain": []
}
]
}代码示例
curl -X POST "https://cloud.heimori.cn/v1/script/convert" \
-H "Authorization: Bearer sk-heimori-..." \
-H "Content-Type: application/json" \
-d '{
"text": "ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ ᠪᠢᠴᠢᠭ"
}'