Skip to main content

An efficient C++ incremental parser for multi-choices grammars (generalization of the trie structure) with Python bindings.

Project description

Coverage

Multi-choices Parser

Overview

Multi-choices Parser is a C++ efficient incremental parser for multi-choices grammars with Python bindings (3.8+). These grammars are defined as a composition of lists of choices, where each choice is a literal string and can possibly be empty (grammar form below). This parser is optimized for scenarios where the size of the lists of choices is very large, such as representing entities preceded by a determiner.

Here is the type of grammar handled by this parser:

start: list1 list2 ... listn
list1: choice1_1 | choice1_2 | ... | choice1_k1
list2: choice2_1 | choice2_2 | ... | choice2_k2
...
listn: choicem_1 | choicem_2 | ... | choicem_kn

This parser is a generalization of tries, and more precisely a concatenation of tries. In fact, it is equivalent to a trie when $n=1$.

Installation

pip install multi-choices-parser

Features

  • Handle large lists of choices efficiently (e.g. millions of choices).
  • Incremental parsing: Each node and its transitions can be accessed at any moment of the parsing.
  • Extensive testing
  • Support for all Python versions >=3.8
  • Support for Linux, Windows and MacOS

Usage

To use the MultiChoicesParser, follow these steps:

  1. Initialize the parser with a list of choices.
  2. Use the step method to feed characters to the parser.
  3. Check the success flag to determine if the parsed string is correct after feeding the End symbol.
  4. Reset the parser state using the reset method if needed.

Example

from multi_choices_parser.parser import MultiChoicesParser, DEFAULT_END_SYMB

# Define your list of choices
l = [
    ['the', 'an', "a", ""],
    ['orange', 'apple', 'banana']
]

# Initialize the parser
p = MultiChoicesParser(l)

# Parse a string (don't forget to add the End symbol)
for i, c in enumerate(tuple("anapple") + (DEFAULT_END_SYMB, )):
    print('Step %s' % i)
    print("Authorized characters:", sorted(p.next()))
    print('Adding character:', c)
    p.step(c)
    print("State: Finished=%s, Success=%s" % (p.finished, p.success))
    print()
Example Output
Step 0
Authorized characters: ['a', 'b', 'o', 't']
Adding character: a
State: Finished=False, Success=False

Step 1
Authorized characters: ['a', 'b', 'n', 'o', 'p']
Adding character: n
State: Finished=False, Success=False

Step 2
Authorized characters: ['a', 'b', 'o']
Adding character: a
State: Finished=False, Success=False

Step 3
Authorized characters: ['p']
Adding character: p
State: Finished=False, Success=False

Step 4
Authorized characters: ['p']
Adding character: p
State: Finished=False, Success=False

Step 5
Authorized characters: ['l']
Adding character: l
State: Finished=False, Success=False

Step 6
Authorized characters: ['e']
Adding character: e
State: Finished=False, Success=False

Step 7
Authorized characters: [End]
Adding character: End
State: Finished=True, Success=True

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For any queries or bug reports, please open an issue on the GitHub repository ;)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

multi_choices_parser-0.9.73-cp313-cp313-win_amd64.whl (105.7 kB view details)

Uploaded CPython 3.13Windows x86-64

multi_choices_parser-0.9.73-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.73-cp313-cp313-macosx_11_0_arm64.whl (99.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

multi_choices_parser-0.9.73-cp312-cp312-win_amd64.whl (105.7 kB view details)

Uploaded CPython 3.12Windows x86-64

multi_choices_parser-0.9.73-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.73-cp312-cp312-macosx_11_0_arm64.whl (99.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

multi_choices_parser-0.9.73-cp311-cp311-win_amd64.whl (105.6 kB view details)

Uploaded CPython 3.11Windows x86-64

multi_choices_parser-0.9.73-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (139.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.73-cp311-cp311-macosx_11_0_arm64.whl (99.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

multi_choices_parser-0.9.73-cp310-cp310-win_amd64.whl (104.5 kB view details)

Uploaded CPython 3.10Windows x86-64

multi_choices_parser-0.9.73-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.73-cp310-cp310-macosx_11_0_arm64.whl (97.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

multi_choices_parser-0.9.73-cp39-cp39-win_amd64.whl (104.5 kB view details)

Uploaded CPython 3.9Windows x86-64

multi_choices_parser-0.9.73-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.73-cp39-cp39-macosx_11_0_arm64.whl (98.0 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

multi_choices_parser-0.9.73-cp38-cp38-win_amd64.whl (104.3 kB view details)

Uploaded CPython 3.8Windows x86-64

multi_choices_parser-0.9.73-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.73-cp38-cp38-macosx_11_0_arm64.whl (97.7 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file multi_choices_parser-0.9.73-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 89f4c5eb6078d36fbb871171a86ecb4c6492f023aaf53ce9cec81ca81f516180
MD5 7a643eadf0dd472d00686bb68851edc2
BLAKE2b-256 db3edae8b70a9ec210ef43ce8f89ab19459d6a7abd4b24e2b968bfe9f7f3d890

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ceddb0b57b42b6f9767de8c4c1851c2f501ad9f41deea14881bafe3ca5e18b84
MD5 71d6a6e8a452f71b5cfc7b757d262980
BLAKE2b-256 27b4b276970d84e418e8adc65e6244b8a2131edbe92f3cdfa8bc453a3d73a4ce

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2533fe91b5ac8462346bf0b9c109c1fb11120085e17bd79ffe4f5c9cb0d2736c
MD5 1371fb528d0bfc6388ebb846c1bfa4b5
BLAKE2b-256 3f9bc4e7e6bc893f30cd215607fa7ef281c5264d35063aee381ae614afdbd454

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a21c775f335aa78579072b5b4526bec4d3201fc4a9fe28e1a7cce0d387f0f209
MD5 2c4ebf032f3b92d608b8eb145c08f21b
BLAKE2b-256 b5a0798d4351afea0fd6267b35daec3846fcb883df28bda3108fcfd5617acf84

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a532b74410332fe897c79b9dcc040d7ed98750c639c0137a9e50f21665064e3d
MD5 a494c834f5956ff73f6507d285772d44
BLAKE2b-256 9ce5d5f447e7871500ae08aba8966c4ab8cfd611dca13e932839e75e2c2b9759

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee936e6d0961a501f8310eb917e307531168c0fca932297823413803ed654cf6
MD5 92cc31e09d452b3565c88c38a66bdb75
BLAKE2b-256 fd5dcaf68cdfceec5b80d29a5ed7b0df3e355425697133441c97f2dcc5ad1c5f

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2b44978bc37fb3a085b1c7c94df8bdb7dd353cfa24d0d5c0ab70a6ef8adc1db3
MD5 f44f683fdee06e511c968ddef85190da
BLAKE2b-256 a9896310acae65d2c69bc7100332811bd4386ea66cd3a3dce01a327642a0c7d4

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 70d911c9be7f49f2fed1efa4573133a90ff991c1a762a6f9146eb4e90d85b9a6
MD5 1777813a6dba6758c8a7a60fe68a2f3e
BLAKE2b-256 039a45beb5f166e8ffb027c0a7ce05f97940d5986ecbdf046127a877d374936c

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fa1c80ba6b3d1976722e930fc21d8658b272eb2b91ffc3ec294cde1f555c51fc
MD5 2727c50f420c4949be1057e284f37b74
BLAKE2b-256 6022ae779bfc5778f587b449df06f1c59af2c318e13a7b72a5d4600a9b28691b

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 05c1953bf6c5ae747aa509b0c9ad99565364daf16d078e8976c10d34c3713435
MD5 931dda5596f28de52b73efce07f8c7b0
BLAKE2b-256 3cc304adc2a89a21c93cb7dbf5ace602a5994527bbb5e79a9509068635a42957

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f6e7a5d93af0d43e1d733da18ada306b887911197772090a838d8f28b39a655
MD5 9d8d3dff472996544ce910e5a54cc32f
BLAKE2b-256 9a98697422aa012215a712d233ac54c1a3b407262b6b655d0bd10c075d3a8751

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b34653c3b824f94b5ad2afc0f9f3e9e42d99b979cc29d8b39af6c3a62feecef
MD5 4c362701209fb5d2cd4d818f358ab726
BLAKE2b-256 cee36b67c4d7e3c24430d61584dbeff7babbe81e97d20438779b923b45eff18f

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 79581d85c86ee1f602bf5474a220691fc6a8685a57aeb98dfe018799eb5ff4af
MD5 5ec5d38fe5a5d617de5d70434edd52a7
BLAKE2b-256 112d7d082f0e6d1b920130f43939fb1d6aa336b445c02faf3c33e198b81d4c20

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16fc5ca798bfc576ed7fb619ffeb7cb3dd217c97b6f820bb2f7780011fad730c
MD5 e5d11661b9fc2690288547eb12b11dbf
BLAKE2b-256 b0dcfb79bbb53833699d23e704ca1434d9df1815e13aa782d0024c68fc35d261

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c236a654fee7b415518555a51cad3ffbc3084675467d6b409bbc98a304710e9c
MD5 1dcefd1b295ed7c9c4917408119fbd73
BLAKE2b-256 1d81ca4da9b7e5034ed4bde43d75f2cba34fc192d7f23b10835263ab31e8fa73

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c5924d927f9fe15c914622851ba949aee02ceca28630cbd0a7c63e0922b59492
MD5 5c8b85c0d4acee2f0b296464b0c817e8
BLAKE2b-256 acc5cc06f3b50c16f9a8cf3ee4db451e8507f6ba01bb0bcaf5ea466c4bb7ca7e

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 786729673c2127ca2742c64da8b04dbf0d50519728b6f3fc49e959fdafa8d86f
MD5 5881ac8969e7853aa73fe5eab117c44e
BLAKE2b-256 897d17c6892f6f2450a48f7cf36e37996bf77b8298ac524c05fbe25bd286a8d4

See more details on using hashes here.

File details

Details for the file multi_choices_parser-0.9.73-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.73-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 231fcc082044a8c4dfb843d819341975c8f1d42601bea113d2bc833f6e2c741b
MD5 4e4914e07efb83a6f68a02fdd2f1df07
BLAKE2b-256 096f9acacc71c534d21bc0c6a89e15748b9cf75f12599edb1aae62731a86a052

See more details on using hashes here.

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