Skip to main content

sbl2py - A Snowball-to-Python Compiler

sbl2py translates code written in the Snowball string processing language into Python:

import sbl2py
import sbl2py.utils

sbl_code = """
externals ( stem )
define stem as (
    backwards ( ['ly'] delete )
)
"""
py_code = sbl2py.translate_string(sbl_code)
module = sbl2py.utils.module_from_code('demo_module', py_code)
print module.stem('fabulously')

Output:

fabulous

Features

sbl2py should support all of the Snowball features that are commonly used. In particular, all features used by the stemming algorithms from the Snowball stemmer package are supported.

Installation

Installing sbl2py is easy using pip:

pip install sbl2py

Usage

The easiest way to translate a Snowball file into a Python module is using the sbl2py script which is automatically installed with sbl2py:

sbl2py SNOWBALL_FILE PYTHON_FILE

See sbl2py --help for the available options.

You can also use sbl2py from within Python. The sbl2py module offers two functions that translate Snowball code from a string (translate_string) or a file (translate_file) and return the corresponding Python source as a string. If you want to execute the code, simply use the module_from_code function of the sbl2py.utils module.

The generated Python modules export all routines from the original Snowball code that are listed in the externals section. That is, if you have externals ( stem ) in your Snowball code and store the generated Python module in a file called mystemmer.py then you can call the stem routine as follows:

import mystemmer
print mystemmer.stem('foobar')

License

sbl2py is covered by the MIT License. The Snowball source code and the word lists in the test directory are covered by the BSD-3 License. Please see the LICENSE file for details.

Release files for sbl2py 0.1.0-2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sbl2py 0.1.0-2
File Size Uploaded
sbl2py-0.1.0-2.tar.gz 17.2 kB Details

Release files / sbl2py-0.1.0-2.tar.gz

Download URL sbl2py-0.1.0-2.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
39cc0ed71fb77cfe1007c9c94e5b78a294f255f8c73a6998f6c889dafc5dcb72
BLAKE2b-256 checksum
How to use checksums
74c85c06bbaa104683ecc0a814dbc651cea09a38afed02bdf5e5017e7a185940
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0-2 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page