Skip to main content

Python library for Pinyin searching

Reason this release was yanked:

写错GitHub actions了,只上传了源码

Project description

Upload Python Package PyPI version PyPI - Python Version PyPI - License

PinIn Python

基于PinIn4Cpp的Python封装,提供C++的性能的同时用python的方式使用PinIn4Cpp

特性

完全基于PinIn4Cpp的C API,因此相比C++版本功能略有减少

  • 提供Pythonic的封装,而不必调用原始的C API
  • 高效的构建和即时搜索性能
  • 可配置的预设键位方案和模糊音方案

安装

pip install PinInPy

示例

注意:拼音字典文件(pinyin.txt),需要自行准备,也可以从pinyin-data中下载直接使用

import PinInPy
# BEGIN是前缀匹配,也就是根据字符串开头开始匹配
tree = PinInPy.TreeSearcher(PinInPy.Logic.BEGIN, "pinyin.txt")
tree.put_string("佐城雪美")
tree.put_string("游佐梢")
tree.put_string("市原仁奈")

print(tree.execute_search("zcxm"))#根据zcxm搜索 打印: ["佐城雪美"]
print(tree.execute_search("zchenxm"))#测试无模糊音时 打印: []

pinin = tree.get_pinin()# 获取PinIn对象,可以用于配置依赖PinIn对象的TreeSearcher
pinin.get_config().set_fEng2En(True).commit()# 设置eng -> en的模糊音
# 这时候en == eng
print(tree.execute_search("zchenxm"))# 打印: ["佐城雪美"]

pinin.get_config().set_keyboard(PinInPy.Keyboard.MICROSOFT).commit()# 设置键位为微软双拼
# y b(ou) z o(uo)  u(sh) k(ao) == you zuo shao
print(tree.execute_search("ybzouk"))# 打印: ["游佐梢"]

# 可以根据已有的PinIn对象去构造新的搜索树,PinIn上的配置是会被共享的 CONTAIN是部分匹配,部分匹配则是可以从任意位置开始匹配
# 通常部分匹配的性能更差
tree2 = PinInPy.TreeSearcher(PinInPy.Logic.CONTAIN, pinin)
tree2.put_string("佐城雪美")
tree2.put_string("游佐梢")
tree2.put_string("市原仁奈")
tree2.put_string("serika")
# r f(en) n l(ai) == ren nai
print(tree2.execute_search("rfnl"))# 因为是部分匹配,所以后面会被匹配仁奈 打印: ["市原仁奈"]
# 注意! 双拼是成对匹配的,如果只有奇数个拼音音素输入则不会匹配任何中文
print(tree2.execute_search("r"))# 打印: ["serika"]

注意事项

不包含PinIn4Cpp中的ParallelSearch,拼音格式化功能,Keyboard自定义(只能使用预设),从内存中加载字典文件,从内存中加载二进制序列化文件的功能 PinIn类也不暴露拼音获取功能

理论上是平台无关的,但是GitHub Actions只构建了Linux,Windows,MacOS的Wheel包,如果你的目标平台不是其中之一的话可以自行尝试下载源代码,配置CMake,配置C/C++编译器,用pip install .安装

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pininpy-1.0.0.tar.gz (8.4 MB view details)

Uploaded Source

File details

Details for the file pininpy-1.0.0.tar.gz.

File metadata

  • Download URL: pininpy-1.0.0.tar.gz
  • Upload date:
  • Size: 8.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pininpy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 afadebca8816e5414bc1168e8942686ee29dd631c7e1710c0b89c5e15b3ac0f3
MD5 ca962aaf9cc352119044c8875e3dcdb0
BLAKE2b-256 33a4b76b97df4bd8127adc3f1876c5e016cc14fa8e288b69e98226acd1985b8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pininpy-1.0.0.tar.gz:

Publisher: python-publish.yml on KagiamamaHIna/PinInPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page