# YanApi **Repository Path**: TunaFish2C/yan-api ## Basic Information - **Project Name**: YanApi - **Description**: # Yan Api 文言文分词,独立翻译。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-10-29 - **Last Updated**: 2023-12-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: Flask, 文言文, API ## README # Yan Api 文言文分词,独立翻译。 # 实现 基于 jiayan 文言文库, 对文言文进行分词, 然后调用百度翻译得到字词的含义。 # 安装依赖 ## 安装所有依赖库 ``` pip install -r requirements.txt ``` 安装过程中需要编译 Kenlm。本项目使用的 Kenlm 已被修改,可以正常在Windows上编译, 只需要安装 Visual C++ Build Tools 14.0。 ## 下载语言模型 [百度网盘](https://gitee.com/link?target=https%3A%2F%2Fpan.baidu.com%2Fs%2F1PXP0eSQWWcNmAb6lkuB5sw) 提取码: `p0sc` 来源: [甲言/Jiayan Github仓库](https://github.com/jiaeyan/Jiayan) 将压缩包内 `jiayan_models` 文件夹解压到根目录, 使得根目录下有一个名为 `jiayan_models` 的文件夹, 里面包含 `jiayan.klm` 等文件。 # 配置 本 API 调用了百度翻译 API, 需要申请百度翻译 API 权限, 你需要得到appid 和 secret。 程序运行一次后自动生成config.json,形如 ```json { "api_debug": false, "api_ip": "0.0.0.0", "api_max_task": 50, "api_port": 8544, "appid": "12345678912345678", "secret": "XXXXXXXX_XXXXXX_XXXX" } ``` 然后退出。你可以更改配置。 # 运行 ``` python app.py ``` 本服务只能以上述方法启动。 # 调用 ## 创建翻译任务 ``` POST /task/new/ ``` ### 参数(JSON) ```json { "id": 114514, "text": "是故内圣外王之道,暗而不明,郁而不发,天下之人各为其所欲焉以自为方。" } ``` ``` id: 数字类型的任务ID,不可与未结束的任务重复 text: 字符串类型的翻译内容 ``` ### 返回(JSON) ```json { "code": 200, "message": "success", "hint": "task running, GET /task// to get result", "bad_arguments":[] } ``` ``` code: 标准HTTP状态码 message: 语义化提示信息 hint: 可阅读的提示信息, 不一定存在 bad_arguments: 在参数错误时指出错误的参数和错误原因, 不一定存在 (举例:{ "id": "wrong_type", "text": "missing" }) ``` ## 查询翻译任务结果 ``` GET /task// ``` ### 返回(JSON) ```json { "code": 200, "message": "success", "status": "end", "data": [ { "after": "这", "original": "是" } ] } ``` ``` code: 标准HTTP状态码 message: 语义化提示信息 status: 任务状态 ["ready", "running", "end", "error"] data: 如果 status = end, 将会返回翻译结果。 其中每一项一定有original属性, 如果有after属性,那么表示已经翻译, 结果为after。 ``` 当 `status` 为 `"end"` 或 `"error"` 且查询过后, 该任务被永久移除。