A high performance multiple functional word matcher
Project description
Matcher Rust Implement PyO3 binding
Usage
Python usage is in the test.ipynb file.
import msgspec
from matcher_py import Matcher, SimpleMatcher # type: ignore
from extension_types import MatchTableType, SimpleMatchType, MatchTable, MatchTableDict, SimpleWord, SimpleWordlistDict
msgpack_encoder = msgspec.msgpack.Encoder()
matcher = Matcher(
msgpack_encoder.encode(
{
"test": [
MatchTable(
table_id=1,
match_table_type=MatchTableType.Simple,
wordlist=["xxx"],
exemption_wordlist=[],
simple_match_type=SimpleMatchType.MatchFanjian | SimpleMatchType.MatchDeleteNormalize
)
]
}
)
)
print(matcher.word_match("xxx")) # {"test": "[{"table_id":1,"word":"xxx"}]"}
print(matcher.word_match_as_string("xxx")) # "{"test": "[{"table_id":1,"word":"xxx"}]"}"
print(matcher.batch_word_match_as_string(["xxx", "xx"])) # ["{"test": "[{"table_id":1,"word":"xxx"}]"}"]
simple_matcher = SimpleMatcher(
msgpack_encoder.encode({
SimpleMatchType.MatchFanjian
| SimpleMatchType.MatchDeleteNormalize: [
{
"word_id": 1,
"word": "xxx"
}
]
})
)
print(simple_matcher.simple_process("xxx")) # [{"word_id":1,"word":"xxx"}]
print(simple_matcher.batch_simple_process(["xxx", "xx"])) # [[{"word_id":1,"word":"xxx"}], []]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
matcher_py-0.1.0.tar.gz
(406.1 kB
view hashes)
Built Distribution
Close
Hashes for matcher_py-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cb650daae96a1d6fd33fe9351285b85e108980355f6fb4e4cd9fc0550443cc0 |
|
MD5 | 6e5f6b75c03b366f7f9eaf0ffe769e89 |
|
BLAKE2b-256 | 3de2a0617942089a43dd318ba2323198344b1f7c8a97cd1b4bd9c8fa45d7fccc |