Skip to main content

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


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)

Uploaded Source

Built Distribution

matcher_py-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

Supported by

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