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.72-cp313-cp313-win_amd64.whl (105.7 kB view details)

Uploaded CPython 3.13Windows x86-64

multi_choices_parser-0.9.72-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.72-cp313-cp313-macosx_11_0_arm64.whl (99.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

multi_choices_parser-0.9.72-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

multi_choices_parser-0.9.72-cp311-cp311-win_amd64.whl (105.5 kB view details)

Uploaded CPython 3.11Windows x86-64

multi_choices_parser-0.9.72-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (139.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

multi_choices_parser-0.9.72-cp310-cp310-win_amd64.whl (104.4 kB view details)

Uploaded CPython 3.10Windows x86-64

multi_choices_parser-0.9.72-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.72-cp310-cp310-macosx_11_0_arm64.whl (97.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

multi_choices_parser-0.9.72-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

multi_choices_parser-0.9.72-cp39-cp39-macosx_11_0_arm64.whl (97.9 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.8Windows x86-64

multi_choices_parser-0.9.72-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.72-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.72-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9576300f71ba688f799832e8b86b3cb24ea74cde29aa4e70ac63ec7545e32790
MD5 4310ad894e742bcafd2aa5967f508ef1
BLAKE2b-256 f3f273e929b894fe379be5e1b8d373c9acf66c5b34da3f886edbe22ff8725593

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c99dae2ba228c9362648ed66bd9790df07a71176f22938595487605b489a8dc8
MD5 f953d9e32a2d13873fd1e0b4c1c00e67
BLAKE2b-256 8b8df0a244c59e13e4591e5be9f0793a22e3cde6b631801f9473e96fe44c76bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3dfd87c968a6e5618a0cacc3d29fa244cf427208829eeda82802fd60250ea1b3
MD5 8208e1ce6463a28fd59f8f4303bf6406
BLAKE2b-256 db9d8ea1f8a87282da07b0d5044c682566a68eced933bb675c8936400bb72a54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 28ac8cea47639b434fc88e143f5d38a0bd5ab4ce9a040a036e532896185d672b
MD5 051cbfe76d429c950af40562747ecca6
BLAKE2b-256 07134c601c9336b7a83e762937c2d75823964a9a9773903cba2696ec59107dbf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 441ef6dd784c9d7fbf0effe66f2e910ad308604749924e0dccec79fd24cfdf2e
MD5 ffef0dab46846436aa3a123ed17a108d
BLAKE2b-256 986a5c90c3b19013aa02b40ed6ef193213bfb4ad92e4500c8e1009e712c0d6db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 277ed1e6e4c7044313281caa5c20cb09eab518f27271001afea748793acc26a9
MD5 9db8bc1329571ce3e1705c2a42960e04
BLAKE2b-256 519810331d2da4c0c036720f1cd41a60f33cf35a4ac2aad963dd58e486d97ccb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 65725c593363b8c207748478ca966e5fc0288118b95c2e6b7cc338003417a185
MD5 9f2fe9032cbf267c1bbc68b1430956e1
BLAKE2b-256 47c05b47daed1dd6cff64c602cdcefda285eacfdf71f43d0452ed2f68e17ae9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4700eab86215bd4f0da9fcea0650e5336bc22d62a77625b2d3d1b1a83081b0d4
MD5 c76ab279e1dbb7217aaed6cb5a9eecbc
BLAKE2b-256 aa3cfb13affb1061050fb0f2988d1fdd0f37943e17abf1644ac681d6cda45615

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7554b9928b663952d50dad2be070b33eac12a7cf0a5d0237ca273f075e598d09
MD5 2042f0a2c97899015553154a6bbf6890
BLAKE2b-256 ab147a99908c455ed355563c1a59c3953fd2e1e0b8bd3699f616adf44f31c019

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3f991c2f753500e68735d64ccfe633af1b8f50a283911157c85c42f01d1922e2
MD5 910593bedb1033dc2b372bfc9adb7026
BLAKE2b-256 8927c838719fe64501cb9dcf0fcda9dd021137b31555bac3e2fc70b62cd3b49f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86a353399cd93d3518ab128129ce29f46337352f3c7321cada52750024017491
MD5 8bbb36cf32484a263cf41773a0965251
BLAKE2b-256 1f27f1de3a94af3fea6da5954cdacaafc7c879bfdc113c45db4030885693dfce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9065615c4a888d8246aa281f3122e9b850823649f1b0d6f9210b0f620a222613
MD5 0beb4c511943188fc413ec4a550c9265
BLAKE2b-256 7c5f146b1f4818113aa5aa85d75cd8a9421b62c419e6c28a447f75dde959e9da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 138483583774d83fc251ee3d1dbac0a94931bfba522ee83ef54ea18cd61b8691
MD5 b695265af41c7f4f6d9a99a875c74463
BLAKE2b-256 1f3b4ec1ac5f79ccb89a9d21d5d036aa4cd7be76814be02fdaeef5829534f66c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21ad352a31dcf6a96a26e4a33a04baf4f5ed47de825430ac96e86b2d3592f40d
MD5 83b7a93e44109f8cf6933cbb2b79d840
BLAKE2b-256 af2bfc617d5d10b40eda3d760c50204be8352609bdb79c7f0371b153efa9737d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f09822a1e715fd3d10ac727836e6febc1bb4596ddc667c7f94c0c50738b48029
MD5 25d77104057421f0bef3f8ac1c66420a
BLAKE2b-256 b70cc4b90e5eaed9a95f08b6f09bcd4f8283e60699a54aaf552c4ba8c30045b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fb25b2094039a7099fb276b9a8210e9907eb88cbb8caf266d4c76efb9b7e86d5
MD5 d666c6085f3ea41fd679b2aabff74b54
BLAKE2b-256 9acf2d09449a30acd5091c0985d47910c02e03e718fef17320e237dabdc1d37d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c90a90a87d968b74ee2ac2c3cb1a0cc3166dc1ae40eca4cadde9e1be2f29e96b
MD5 e69546eac2d36e2e6ca2957ca2f22846
BLAKE2b-256 af688872313ebb181021e32fde3033c48f6df8d9d2c87b6f56b991bb74e7788e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multi_choices_parser-0.9.72-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef2cf24b5f3633bf77d5fa6412a4ec53230123bb6400ebe1f6faa824aedbc687
MD5 0ee8fde6c21c5619dca61d3db423bdd4
BLAKE2b-256 f956dd75a6f5504b23767809160eadfcc3b2872c9ec220b8c6e635a453ae9d8c

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