Skip to main content

Parses unstructured recipe ingredient text into standardized quantities, units, and foods

Project description

ingredient-slicer

Python 📦 package for extracting quantities, units, and food words from unstructured recipe ingredients text.

ingredient-slicer works by standardizing the input text and then applying a set of rules and heuristic methods to parse out quantities, units, and food words from unstructured recipe ingredients text. ingredient-slicer was designed to provide a robust and lightweight method for parsing recipe ingredients text without relying on any external dependencies or NLP/ML models. That being said, it is not perfect and can always be improved upon.

Table of Contents:


Installation:

ingredient_slicer can be downloaded from PyPI via pip like so:

pip install ingredient-slicer

Usage:

Provide a string to the IngredientSlicer class and thats it. Invoke the to_json() method to return the parsed ingredient.

import ingredient_slicer

slicer = ingredient_slicer.IngredientSlicer("2 (15-ounces) cans chickpeas, rinsed and drained")

slicer.to_json()

{   
    'ingredient': '2 (15-ounces) cans chickpeas, rinsed and drained', 
    'standardized_ingredient': '2 cans chickpeas, rinsed and drained', 
    'food': 'chickpeas', 

    # primary quantity and units
    'quantity': '30', 
    'unit': 'ounces', 
    'standardized_unit': 'ounce', 

    # any other secondary quantity and units found in the string
    'secondary_quantity': '2', 
    'secondary_unit': 'cans', 
    'standardized_secondary_unit': 'can', 

    'gram_weight': '850.49', 
    'prep': ['drained', 'rinsed'], 
    'size_modifiers': [], 
    'dimensions': [], 
    'is_required': True, 
    'parenthesis_content': ['15 ounce']
}

Individual ingredient components can also be found using methods like food(), quantity(), or unit()

import ingredient_slicer

slicer = ingredient_slicer.IngredientSlicer("3 tbsp unsalted butter, softened at room temperature")

slicer.food() 
>>> 'unsalted butter'

slicer.quantity() 
>>> '3' 

slicer.unit() 
>>> 'tbsp'

slicer.standardized_unit() 
>>> 'tablespoon'

slicer.prep() 
>>> ['room temperature', 'softened']

Contributing/Issues:

If you find a bug or have an idea for a new feature, please open an issue or submit a pull request.

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

ingredient_slicer-1.1.12.tar.gz (123.7 kB view details)

Uploaded Source

Built Distribution

ingredient_slicer-1.1.12-py3-none-any.whl (76.5 kB view details)

Uploaded Python 3

File details

Details for the file ingredient_slicer-1.1.12.tar.gz.

File metadata

  • Download URL: ingredient_slicer-1.1.12.tar.gz
  • Upload date:
  • Size: 123.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for ingredient_slicer-1.1.12.tar.gz
Algorithm Hash digest
SHA256 143da1852c7916ffba23a541449f1179d4058d05d5a7afdae09c3f8481d00614
MD5 ace225e2c84f2a45894c3580c1465de8
BLAKE2b-256 51dbbd4189087fbbfbe4c6dc22824c8bdd5fdc0549912c2b64b6bcef50ddd62c

See more details on using hashes here.

File details

Details for the file ingredient_slicer-1.1.12-py3-none-any.whl.

File metadata

File hashes

Hashes for ingredient_slicer-1.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 70c3d396aa344f4b65aa4dca965b013f50cdbc21b70487c573db0ddf64778db2
MD5 d9f30da57c28102509c7bea3c912834a
BLAKE2b-256 0489c388a9f29fb8840ec4ded489824ea9c16809a89285e1354fe9734604c085

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