word2num


Nameword2num JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/doppio/word2num
SummaryConverts numbers expressed in words to numerical values.
upload_time2023-11-25 00:42:59
maintainer
docs_urlNone
authorBryson Thill
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements thefuzz python-Levenshtein
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # word2num 💬 → 🔢 <!-- omit in toc -->

![PyPI Version](https://img.shields.io/pypi/v/word2num?logo=pypi&logoColor=white&style=flat-square)

`word2num` is a Python package for converting numbers expressed in natural language to numerical values. It supports:

- Fractions
- Decimals
- Negative values
- Large numbers into the quintillions
- Digit sequences
- Fuzzy string matching

---

## Table of Contents <!-- omit in toc -->
- [🛠️ Installation](#️-installation)
- [💻 Usage](#-usage)
- [🐻 Fuzzy String Matching](#-fuzzy-string-matching)
  - [Default Fuzzy Threshold](#default-fuzzy-threshold)
  - [Custom Fuzzy Threshold](#custom-fuzzy-threshold)
  - [Disable Fuzzy Matching](#disable-fuzzy-matching)
- [🌐 Language Support](#-language-support)
- [🤝 Contributing](#-contributing)
- [📃 License](#-license)

---


## 🛠️ Installation

To use `word2num`, you must first install it. You can do this using pip by running the following command in your terminal:

```
pip install word2num
```

## 💻 Usage

Once installed, you can use `word2num` to convert numbers expressed in natural language to numerical values. To parse a single string, use the `word2num` convenience function:

```python
from word2num import word2num

word2num("fifty-seven thousand four hundred and twenty-one")  # 57421
```

If you need to parse multiple strings, you can create your own instance of `Word2Num` and call its `parse` method:

```python
from word2num import Word2Num

w2n = Word2Num()
w2n.parse("one hundred and one")     # 101
w2n.parse("seventeen billion")       # 17000000000
w2n.parse("negative eight")          # -8
w2n.parse("half")                    # 0.5
w2n.parse("one and three quarters")  # 1.75
w2n.parse("one three three seven")   # 1337
```

Note that these functions will return `None` if a valid numerical value couldn't be interpreted.

## 🐻 Fuzzy String Matching

`word2num` uses fuzzy string matching to help parse misspelled number words.

### Default Fuzzy Threshold

By default, `word2num` uses a fuzzy threshold of 80, which means that it will match a word to a number if the fuzzy score is 80 or higher.

### Custom Fuzzy Threshold

You can change the fuzzy threshold by passing a `fuzzy_threshold` parameter to the `word2num` function or to the `Word2Num` class constructor:

```python
# Using the word2num function
word2num("soxteeeen", fuzzy_threshold=60) # [16]

# Using the Word2Num class
w2n = Word2Num(fuzzy_threshold=60)
w2n.parse("twoo hunrdered and twienty-too")  # [222]
```

### Disable Fuzzy Matching

To disable fuzzy matching (exact matching only), you can set the `fuzzy_threshold` to 100:

```python
w2n = Word2Num(fuzzy_threshold=100)
w2n.parse("two hundered and twinty-two")  # None
```

## 🌐 Language Support

* English
* Spanish

We'd love to add support for other languages. Contributions are more than welcome, so if you're interested in contributing, see the "Contributing" section below!

## 🤝 Contributing

Contributions to `word2num` are more than welcome! If you'd like to contribute, please follow these guidelines:

- Make sure the tests pass by running `pytest` in the root directory of the repository.
- If appropriate, add new tests to cover your changes.
- Follow the existing code style and conventions.
- Create a pull request with your changes.

## 📃 License

`word2num` is released under the MIT License. See `LICENSE.txt` for more information.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/doppio/word2num",
    "name": "word2num",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Bryson Thill",
    "author_email": "bryson@streamliners.dev",
    "download_url": "https://files.pythonhosted.org/packages/b0/19/74026e941148de9f21a3bf4b78c264eeb4eae57079887c39e392329a41c4/word2num-0.1.2.tar.gz",
    "platform": null,
    "description": "# word2num \ud83d\udcac \u2192 \ud83d\udd22 <!-- omit in toc -->\n\n![PyPI Version](https://img.shields.io/pypi/v/word2num?logo=pypi&logoColor=white&style=flat-square)\n\n`word2num` is a Python package for converting numbers expressed in natural language to numerical values. It supports:\n\n- Fractions\n- Decimals\n- Negative values\n- Large numbers into the quintillions\n- Digit sequences\n- Fuzzy string matching\n\n---\n\n## Table of Contents <!-- omit in toc -->\n- [\ud83d\udee0\ufe0f Installation](#\ufe0f-installation)\n- [\ud83d\udcbb Usage](#-usage)\n- [\ud83d\udc3b Fuzzy String Matching](#-fuzzy-string-matching)\n  - [Default Fuzzy Threshold](#default-fuzzy-threshold)\n  - [Custom Fuzzy Threshold](#custom-fuzzy-threshold)\n  - [Disable Fuzzy Matching](#disable-fuzzy-matching)\n- [\ud83c\udf10 Language Support](#-language-support)\n- [\ud83e\udd1d Contributing](#-contributing)\n- [\ud83d\udcc3 License](#-license)\n\n---\n\n\n## \ud83d\udee0\ufe0f Installation\n\nTo use `word2num`, you must first install it. You can do this using pip by running the following command in your terminal:\n\n```\npip install word2num\n```\n\n## \ud83d\udcbb Usage\n\nOnce installed, you can use `word2num` to convert numbers expressed in natural language to numerical values. To parse a single string, use the `word2num` convenience function:\n\n```python\nfrom word2num import word2num\n\nword2num(\"fifty-seven thousand four hundred and twenty-one\")  # 57421\n```\n\nIf you need to parse multiple strings, you can create your own instance of `Word2Num` and call its `parse` method:\n\n```python\nfrom word2num import Word2Num\n\nw2n = Word2Num()\nw2n.parse(\"one hundred and one\")     # 101\nw2n.parse(\"seventeen billion\")       # 17000000000\nw2n.parse(\"negative eight\")          # -8\nw2n.parse(\"half\")                    # 0.5\nw2n.parse(\"one and three quarters\")  # 1.75\nw2n.parse(\"one three three seven\")   # 1337\n```\n\nNote that these functions will return `None` if a valid numerical value couldn't be interpreted.\n\n## \ud83d\udc3b Fuzzy String Matching\n\n`word2num` uses fuzzy string matching to help parse misspelled number words.\n\n### Default Fuzzy Threshold\n\nBy default, `word2num` uses a fuzzy threshold of 80, which means that it will match a word to a number if the fuzzy score is 80 or higher.\n\n### Custom Fuzzy Threshold\n\nYou can change the fuzzy threshold by passing a `fuzzy_threshold` parameter to the `word2num` function or to the `Word2Num` class constructor:\n\n```python\n# Using the word2num function\nword2num(\"soxteeeen\", fuzzy_threshold=60) # [16]\n\n# Using the Word2Num class\nw2n = Word2Num(fuzzy_threshold=60)\nw2n.parse(\"twoo hunrdered and twienty-too\")  # [222]\n```\n\n### Disable Fuzzy Matching\n\nTo disable fuzzy matching (exact matching only), you can set the `fuzzy_threshold` to 100:\n\n```python\nw2n = Word2Num(fuzzy_threshold=100)\nw2n.parse(\"two hundered and twinty-two\")  # None\n```\n\n## \ud83c\udf10 Language Support\n\n* English\n* Spanish\n\nWe'd love to add support for other languages. Contributions are more than welcome, so if you're interested in contributing, see the \"Contributing\" section below!\n\n## \ud83e\udd1d Contributing\n\nContributions to `word2num` are more than welcome! If you'd like to contribute, please follow these guidelines:\n\n- Make sure the tests pass by running `pytest` in the root directory of the repository.\n- If appropriate, add new tests to cover your changes.\n- Follow the existing code style and conventions.\n- Create a pull request with your changes.\n\n## \ud83d\udcc3 License\n\n`word2num` is released under the MIT License. See `LICENSE.txt` for more information.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Converts numbers expressed in words to numerical values.",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/doppio/word2num"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9791c1f0557d5516ec34c3f1a263b00923fd5607848af321e0efe38130411454",
                "md5": "f219fbd187a53ec8f908c73aa63ad561",
                "sha256": "1c30ce2631552857415ebd2aaf8419c9adbd1b26e28aa7299b839bed94dad86a"
            },
            "downloads": -1,
            "filename": "word2num-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f219fbd187a53ec8f908c73aa63ad561",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 17335,
            "upload_time": "2023-11-25T00:42:57",
            "upload_time_iso_8601": "2023-11-25T00:42:57.622486Z",
            "url": "https://files.pythonhosted.org/packages/97/91/c1f0557d5516ec34c3f1a263b00923fd5607848af321e0efe38130411454/word2num-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b01974026e941148de9f21a3bf4b78c264eeb4eae57079887c39e392329a41c4",
                "md5": "512a94be7bb57f4d17e02d32f7eba896",
                "sha256": "e9cf7a73b0207a0c4113b1272811743982c83f13be03639ee800333cc0e5a942"
            },
            "downloads": -1,
            "filename": "word2num-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "512a94be7bb57f4d17e02d32f7eba896",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13386,
            "upload_time": "2023-11-25T00:42:59",
            "upload_time_iso_8601": "2023-11-25T00:42:59.628548Z",
            "url": "https://files.pythonhosted.org/packages/b0/19/74026e941148de9f21a3bf4b78c264eeb4eae57079887c39e392329a41c4/word2num-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-25 00:42:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "doppio",
    "github_project": "word2num",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "thefuzz",
            "specs": [
                [
                    ">=",
                    "0.19.0"
                ]
            ]
        },
        {
            "name": "python-Levenshtein",
            "specs": [
                [
                    ">=",
                    "0.20.4"
                ]
            ]
        }
    ],
    "lcname": "word2num"
}
        
Elapsed time: 0.37543s