用另一种方式说同一个句子。
siaw的Python项目详细描述
换种说法
同一句话有不同的表达方式,有时候需要翻译翻译。
- GitHub: https://github.com/SnailZSJ/SayItAnotherWay
- License: MIT license
- PyPI: https://pypi.org/project/siaw/
- Python version: pypy3, 3.6, 3.7, 3.8
已支持功能列表
功能 | 参数 |
---|---|
拼音转换 | pinyin |
顺序转换 | sequence |
逆序转换 | reverse |
过滤敏感词转换 | filter |
添加间隔符转换 | space_mark |
拆字转换 | chaizi |
反义词转换 | antonym |
同义词转换 | synonym |
同音转换 | homophone |
安装
pip3 install siaw
使用示例
1. 拼音转换
fromsiawimportSayItAnotherWaysentence_pinyin=SayItAnotherWay("阿伟死了")result=sentence_pinyin.translate('pinyin')print(result)
输出
'ā wěi sǐ le'
2. 乱序转换
fromsiawimportSayItAnotherWaysentence_sequence=SayItAnotherWay("汉字的顺序并不一定能影响阅读")result=sentence_sequence.translate('sequence',use_jieba=False)print(result)
输出
'汉的字序顺不并定一影能阅响读'
3. 逆序转换
fromsiawimportSayItAnotherWaysentence_reverse=SayItAnotherWay("汉字的顺序并不一定能影响阅读")result=sentence_reverse.translate('reverse',use_jieba=False)print(result)
输出
'读阅响影能定一不并序顺的字汉'
4. 过滤敏感词转换
fromsiawimportSayItAnotherWaysentence_filter=SayItAnotherWay("违禁词会被过滤,比如巨乳,懂了吗?")result=sentence_filter.translate('filter')print(result)
输出
'违禁词会被过滤,比如**,懂了吗?'
5. 添加间隔符转换
fromsiawimportSayItAnotherWaysentence_space_mark=SayItAnotherWay("这里会加入一些间隔符号。")result=sentence_space_mark.translate('space_mark',use_jieba=False,space_mark='+')print(result)
输出
'这+里+会+加+入+一+些+间+隔+符+号+。'
6. 拆字转换
fromsiawimportSayItAnotherWaysentence_chaizi=SayItAnotherWay("测试拆字结果。")result=sentence_chaizi.translate('chaizi',use_jieba=False)print(result)
输出
'水则 言式 手斥 宀子 丝吉 日木 。'
7. 反义转换
fromsiawimportSayItAnotherWaysentence_antonym=SayItAnotherWay("Python从入门到放弃。")result=sentence_antonym.translate('antonym')print(result)
输出
'Python主入门到坚持。'
8. 同义转换
fromsiawimportSayItAnotherWaysentence_synonym=SayItAnotherWay("Python从入门到放弃。")result=sentence_synonym.translate('synonym')print(result)
输出
'Python打入库及割舍。'
9. 同音转换
fromsiawimportSayItAnotherWaysentence_homophone=SayItAnotherWay("苟利国家生死以,岂因福祸避趋之。")result=sentence_homophone.translate('homophone')print(result)
输出
'煹鷅濄扴狌蟖齮,埼音俘获比娶支。'
10. 测试混合模式转换
fromsiawimportSayItAnotherWaysentence_mixed=SayItAnotherWay("测试多种模式混合结果。")result=sentence_mixed.translate('mixed',use_jieba=False,space_mark=' ',ways=['chaizi','pinyin'])print(result)
输出
'shuǐzéyánshìxīxīhézhōngmùmòyìgōngshuǐkūnrényīkǒusījírìmù。'
TODO
- 提高同、反义词的准确性和词量。
- 提供更简明便捷通用的 API 接口。
- 降低打包后的文件体积。
- ...
致谢
- 项目
标签: