Skip to main content

An efficient C++ incremental parser for multi-choices grammars 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

  • Handles large lists of choices efficiently (e.g. millions of choices).
  • Incremental parsing.

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("apple") + (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.71-cp313-cp313-win_amd64.whl (105.2 kB view details)

Uploaded CPython 3.13Windows x86-64

multi_choices_parser-0.9.71-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (137.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.71-cp313-cp313-macosx_11_0_arm64.whl (98.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

multi_choices_parser-0.9.71-cp312-cp312-win_amd64.whl (105.2 kB view details)

Uploaded CPython 3.12Windows x86-64

multi_choices_parser-0.9.71-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (137.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.71-cp312-cp312-macosx_11_0_arm64.whl (98.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

multi_choices_parser-0.9.71-cp311-cp311-win_amd64.whl (105.1 kB view details)

Uploaded CPython 3.11Windows x86-64

multi_choices_parser-0.9.71-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (139.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.71-cp311-cp311-macosx_11_0_arm64.whl (98.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

multi_choices_parser-0.9.71-cp310-cp310-win_amd64.whl (104.0 kB view details)

Uploaded CPython 3.10Windows x86-64

multi_choices_parser-0.9.71-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (137.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.71-cp310-cp310-macosx_11_0_arm64.whl (97.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

multi_choices_parser-0.9.71-cp39-cp39-win_amd64.whl (104.1 kB view details)

Uploaded CPython 3.9Windows x86-64

multi_choices_parser-0.9.71-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.71-cp39-cp39-macosx_11_0_arm64.whl (97.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

multi_choices_parser-0.9.71-cp38-cp38-win_amd64.whl (103.9 kB view details)

Uploaded CPython 3.8Windows x86-64

multi_choices_parser-0.9.71-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (137.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.71-cp38-cp38-macosx_11_0_arm64.whl (97.2 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d7049a4a99d0ca12ea9fbfbc38cdec9ce0f59878d1e90bf67c5fba48717a3b82
MD5 602d8ba932f6bb2e2c5d59640db9d3d1
BLAKE2b-256 7721799f1aac688d7d97ade29e3292136a30f16ccb56606e1a7b20b45fbc5168

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 823fc5961cd0d3e99eef93a6afa3e01d9391bcfc2de28ad0e7d96b782ad971b9
MD5 13703313a9b8ee9c66eccacbc846a114
BLAKE2b-256 a6a3fd46e5f5d08815d458550d412e6be895c710f6ed1b2daab663fdf7a7418c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 59cfc71b5e6f8b78365973504da23d9e69d20da3faf19cf446dc6dc7bd091773
MD5 0938892db11fa49b7ccdb6d315256b67
BLAKE2b-256 8f365db9dda9507557f70f54b88cc539d680723a813f6a3e40dd124b6e173f6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 110485b0bbfb193e5424d99f6831541118b96239dfadd923b15a5079c7824c17
MD5 4f66bbf21bce87712827ba86c7f4e87d
BLAKE2b-256 089f7d1edaeede23407d782e664c92d4da1b74977d90163dd9dfc66a10eec5c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37649039d64d9cbcadee88d1ea7eca96442dcb65b150cadbb9bdaeb6c620c3a2
MD5 1f56b1eb4493adba0c892a17d29e199a
BLAKE2b-256 69dfe08f3b2b7784aff572f2f2369b7353a052965f2f6659184ac634656393a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f7b95500f4fe4b55d7c53be9d4742d2371ed20d19e918335b2d622b99cbc0b3
MD5 97d330ed910dd519d6836e9c2180fc5c
BLAKE2b-256 57230f2a7ae0f0ca95704f01c5ca2c06a5621349d10389cfdfd7ba1dd405933b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 46f352a8bc5706d515af60eafa1cb03f2f4e9f68571ee33bf4251e1f551cfa4b
MD5 9245ec6c4b7346b8cec23a3740715f04
BLAKE2b-256 a140c48f4c26fd9c490470b1384367b8b1232ec7bc609f41676d4a0a4bfe71a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 08f882b0cc4f4251c9d27840b0340b8441c12c02face2f4b1386c79a930697b4
MD5 20701ef3a2933485885aae314125ae64
BLAKE2b-256 7456b41d184f6d8d4e12f2cdbc11aea16efc09d674e518782a22a678eac704ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4fa84d91fa6008a6b39a31ec4d0bb817bd6be1b0d79855750483a8bfaf22b6f
MD5 4744d0272c7ed588aa200aaf9fbf2e56
BLAKE2b-256 81813c0f03fb411778ae222c7bab082967752d59cf963c0f1ccaa749ff9e4606

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0a0128766102d4c4fa66f311f7cf8b54120a744971fc48807478d67fa5e10674
MD5 9f8883c8fc52ad4f21c4ec2b374040f5
BLAKE2b-256 53ca236475d9d7671014e1c4c7b233ef3dcc95c3390e5eeac51f310120422420

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be6660ce54f2ae7d5bd0cb7877e691e59840fb91dd7705442e0a43b589b293ed
MD5 5ecfd7bedd7ade72e06c91c51bbf583f
BLAKE2b-256 c9576de6b38c2c5bdff470747ad6ec04b6a495f846ffc2a2f401230042af8523

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7cf192d272f9e40f44e004c8f471074594f9fd48649e79a6f8158c86137a5b37
MD5 9e0bd5c6c22d2b1675e8d8291c262450
BLAKE2b-256 e482412892a443619874679f4024d785464128fb90d3f6e1b98a89091ec5f948

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9aa16827d4243e44426920cc24710a6fc4b6e87d9a60432b7f7bf97e37bd8f80
MD5 047bc9843271400d01f574ed03f7ec07
BLAKE2b-256 fdf466fa38c1119ea2b1eeb4d795efd4f1abff57a972090fdf314eef580cb44a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fcbe908be0da5e066b3585c5549e9a119f6c2719ddbbb75149ba8a90e3dc2d46
MD5 bd87ce92eea33d6a7e7c6cb64aa3105a
BLAKE2b-256 25efbefee20eedfcdc50f2d681d711d5dd4d91d6821e6570722f4a8a13fd9367

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 808fd70c4d7a3583ca88189443b4ac4a19fba568d72de755f87c0a7056ded197
MD5 27d585b8eda056e961765b349c69fb2b
BLAKE2b-256 846b2270130cfc10d6113280f70a05c3fa08074eeff6d2908d480d832de4fe79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 07377991477c3e8c0d005cf1a29f94655e03e75ce3d3549b9900e37e347233d4
MD5 c05ad3a220cf8e31698ef62f5b992869
BLAKE2b-256 507e82974b7938f7b6fe6ae2e33c0c145b3b0c0a0e0738044a514e14e878fe88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03f9502ca7fdd0ce76171c2e9be958e4aaeae048dd9fe4e7a3dd5dbcd66e652c
MD5 a1ffd9d781d7d220fdb225357f985d8d
BLAKE2b-256 f319c57cb3a619a8863424788d359bc083fc66f485031cf007583283d423bff4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.71-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 67d65b3be562beed140ce0ec0320035f469510c95cbe71edc22e88ff42b4db96
MD5 263fc47efb19cae7d412baa0e09fae0f
BLAKE2b-256 d680441e27cce2e9084cc6a3c462853a4ba5e6968aa4a28e8eed5ace8a62510d

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