跳转到主要内容

快速英文分词

项目描述

Cover logo

Instant Segment:Rust中的快速英文分词

Documentation Crates.io PyPI Build status License: Apache 2.0

Instant Segment是一个基于Apache-2.0许可的快速英文分词库。它基于Grant Jenks编写的Python wordsegment 项目,该项目又基于Peter Norvig在《Beautiful Data》一书中自然语言语料库数据章节中的代码(Segaran and Hammerbacher,2009年)。

在本存储库包含的微基准测试中,Instant Segment比Python实现快约500倍。API经过精心设计,以便多个分词可以共享底层状态,从而允许并行使用。

工作原理

Instant Segment通过根据单词语料库及其出现频率选择具有最高概率的分割来将字符串分割成单词。

例如,如果“choose”和“spain”比“chooses”和“pain”出现得更频繁,并且“choose spain”比“chooses pain”出现得更频繁,那么Instant Segment可以帮助识别域名“choosespain.com”为“ChooseSpain.com”,这更符合用户意图。

了解我们如何在Instant Domain Search的生产环境中构建和改进Instant Segment以帮助用户找到可以注册的相关域名(点击此处)

使用库

Python (≥ 3.9)

pip install instant-segment

Rust

[dependencies]
instant-segment = "0.8.1"

示例

以下示例假设存在 unigramsbigrams。请参阅示例(RustPython)了解如何构建这些对象。

import instant_segment

segmenter = instant_segment.Segmenter(unigrams, bigrams)
search = instant_segment.Search()
segmenter.segment("instantdomainsearch", search)
print([word for word in search])

--> ['instant', 'domain', 'search']
use instant_segment::{Search, Segmenter};
use std::collections::HashMap;

let segmenter = Segmenter::new(unigrams, bigrams);
let mut search = Search::default();
let words = segmenter
    .segment("instantdomainsearch", &mut search)
    .unwrap();
println!("{:?}", words.collect::<Vec<&str>>())

--> ["instant", "domain", "search"]

查看测试以获取更详细的示例:RustPython

测试

要运行测试,请执行以下操作

cargo t -p instant-segment --all-features

您还可以使用以下命令测试Python绑定

make test-python

项目详情


下载文件

下载适用于您的平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

此版本没有可用的源分发文件。请参阅生成分发存档的教程。

构建分发

instant_segment-0.1.8-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (287.8 kB 查看哈希值)

上传时间 PyPy manylinux: glibc 2.17+ x86-64

instant_segment-0.1.8-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (287.7 kB 查看哈希值)

上传时间 PyPy manylinux: glibc 2.17+ x86-64

instant_segment-0.1.8-cp312-none-win_amd64.whl (155.8 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

instant_segment-0.1.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (286.9 kB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

instant_segment-0.1.8-cp312-cp312-macosx_11_0_arm64.whl (247.3 kB 查看哈希值)

上传时间 CPython 3.12 macOS 11.0+ ARM64

instant_segment-0.1.8-cp312-cp312-macosx_10_12_x86_64.whl (252.0 kB 查看哈希值)

上传时间 CPython 3.12 macOS 10.12+ x86-64

instant_segment-0.1.8-cp311-none-win_amd64.whl (157.1 kB 查看哈希值)

上传时间 CPython 3.11 Windows x86-64

instant_segment-0.1.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (288.2 kB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ x86-64

instant_segment-0.1.8-cp311-cp311-macosx_11_0_arm64.whl (248.8 kB 查看哈希值)

上传于 CPython 3.11 macOS 11.0+ ARM64

instant_segment-0.1.8-cp311-cp311-macosx_10_12_x86_64.whl (253.8 kB 查看哈希值)

上传于 CPython 3.11 macOS 10.12+ x86-64

instant_segment-0.1.8-cp310-none-win_amd64.whl (157.2 kB 查看哈希值)

上传于 CPython 3.10 Windows x86-64

instant_segment-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (288.2 kB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ x86-64

instant_segment-0.1.8-cp310-cp310-macosx_11_0_arm64.whl (248.8 kB 查看哈希值)

上传于 CPython 3.10 macOS 11.0+ ARM64

instant_segment-0.1.8-cp310-cp310-macosx_10_12_x86_64.whl (253.8 kB 查看哈希值)

上传于 CPython 3.10 macOS 10.12+ x86-64

instant_segment-0.1.8-cp39-none-win_amd64.whl (157.9 kB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

instant_segment-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (287.7 kB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ x86-64

instant_segment-0.1.8-cp39-cp39-macosx_11_0_arm64.whl (248.6 kB 查看哈希值)

上传于 CPython 3.9 macOS 11.0+ ARM64

instant_segment-0.1.8-cp39-cp39-macosx_10_12_x86_64.whl (253.9 kB 查看哈希值)

上传于 CPython 3.9 macOS 10.12+ x86-64

instant_segment-0.1.8-cp38-none-win_amd64.whl (157.7 kB 查看哈希)

上传于 CPython 3.8 Windows x86-64

instant_segment-0.1.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (287.6 kB 查看哈希)

上传于 CPython 3.8 manylinux: glibc 2.17+ x86-64

instant_segment-0.1.8-cp37-none-win_amd64.whl (157.2 kB 查看哈希)

上传于 CPython 3.7 Windows x86-64

instant_segment-0.1.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (287.6 kB 查看哈希)

上传于 CPython 3.7m manylinux: glibc 2.17+ x86-64

由以下支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面