Skip to main content

A Snowball-to-Python compiler

Project description

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')

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

sbl2py-0.1.0.tar.gz (16.1 kB view details)

Uploaded Source

File details

Details for the file sbl2py-0.1.0.tar.gz.

File metadata

  • Download URL: sbl2py-0.1.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sbl2py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 87f2463c1ce9d780afb45683cfc3d8b7daa1539ad85cc1c9679e834960585b17
MD5 552b79fa4c69fa3016423a61ece7c937
BLAKE2b-256 c90df29756ac2ffaf2715417c6547c17b380df3a7879459df8a56dfeb39c97b9

See more details on using hashes here.

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