rust'fst'crate的python绑定,提供由有限状态传感器支持的集合和映射。
rust-fst的Python项目详细描述
有关您可能要考虑使用它的原因,请参阅Burntsushi的
很好
tl;dr:
- 使用大于内存集的文件
- 使用Levenshtein自动机执行模糊搜索
安装
- 您需要:
- python>;=3.3,python或pypy>;=2.7,带有开发头 已安装
- 每晚生锈(通过rustup安装)
- 克隆存储库。使用pip install git+...进行安装 不工作 目前
- 运行rustup override add nightly为rustup添加覆盖 使用 存储库的夜间频道
- 运行python setup.py bdist_wheel生成轮子
- 安装车轮时 pip install dist/rust_fst-0.1-py3-none-any.whl
状态
这个包公开了fstcrate的几乎所有功能, 除了:
- 将切片结果search和search_re与 设置操作
- 使用原始传感器
示例
fromrust_fstimportMap,Set# Building a set in memorykeys=["fa","fo","fob","focus","foo","food","foul"]s=Set.from_iter(keys)# Fuzzy searches on the setmatches=list(s.search(term="foo",max_dist=1))assertmatches==["fo","fob","foo","food"]# Searching with a regular expressionmatches=list(s.search_re(r'f\w{2}'))assertmatches==["fob","foo"]# Store map on disk, requiring only constant memory for queryingitems=[("bruce",1),("clarence",2),("stevie",3)]m=Map.from_iter(items,path="/tmp/map.fst")# Find all items whose key is greater or equal (in lexicographical sense) to# 'clarence'matches=dict(m['clarence':])assertmatches=={'clarence':2,'stevie':3}