Skip to main content

A Python port of the Apache Lucene ASCII Folding Filter that converts alphabetic, numeric, and symbolic Unicode characters which are not in the first 127 ASCII characters (the ‘Basic Latin’ Unicode block) into ASCII equivalents, if they exist.

## Project description

Copyright (c) 2017 SpanishDict

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Description: # fold_to_ascii

A Python port of the [Apache Lucene ASCII Folding Filter](https://lucene.apache.org/core/4_0_0/analyzers-common/org/apache/lucene/analysis/miscellaneous/ASCIIFoldingFilter.html) that converts alphabetic, numeric, and symbolic Unicode characters which are not in the first 127 ASCII characters (the “Basic Latin” Unicode block) into ASCII equivalents, if they exist.

## Usage

 python > from fold_to_ascii import fold > s = u'Astroturf® paté' > fold(s) u'Astroturf pate' > fold(s, u'?') u'Astroturf? pate'

## Differences from [JS fold-to-ascii](https://www.npmjs.com/package/fold-to-ascii)

This library always removes astral characters, even when a replacement character is specified. PRs welcome if you want to fix this.

## Differences from unidecode

There are a few Python unidecode libraries out there ([1](https://pypi.python.org/pypi/text-unidecode), [2](https://pypi.python.org/pypi/Unidecode/)). They are based on a Perl program that makes some interesting choices about what to replace, for example, £ (POUND SIGN) is replaced with the string PS. Also, they do not allow specifying a replacement character to use other than the empty string for unmapped characters.

## Development environment

 shell $virtualenv -p python3 ~/.local/venvs/fold_to_ascii$ source ~/.local/venvs/fold_to_ascii/bin/activate $pip install -r requirements.txt  ## Test  shell$ make lint && make test

## Release

Requires a [pypi](https://pypi.org/) account.

1. Bump the version in setup.py. 1. Build and upload:

 shell $python setup.py sdist bdist_wheel$ twine upload dist/*

Keywords: ascii unicode sanitize diacritics fold folding ligatures Platform: UNKNOWN Description-Content-Type: text/markdown

## 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 Distribution

fold_to_ascii-1.0.2-py3-none-any.whl (23.2 kB view hashes)

Uploaded py3