Ingredients Validator

Recipe Retriever is meant to be a very simple utility that updates my Obsidian vault so I can hastily make meal plans and grocery lists. How did I find myself in a situation where I wanted to write what is basically a lexer for ingredients? This post covers a bit more about that, but it boils down to I wanted to be able to abstract a single ingredient amount / description into individual parts.

The Issue

I was seeing scenarios where the generator was churning out garbage because it didn’t recognize certain text patterns, and it couldn’t distinguish commonalities between ingredients that would be the same but are written differently.

This tempted me to get access to a GPT API because it would be no problem to create a standardized ingredient from the various ways it can be written by a human, as they have enormous data training sets. I decided against that (for some reason), so I wrote what is essentially an ingredient list compiler. More specifically an ingredient type, quantity, and unit of measure lexer.

What does the Validator Do?

The Validator’s primary role is to complain when it doesn’t recognize ingredients. It’s meant to help me generate accurate and organized grocery lists.

It’s composed of a set of classes and functions that accepts an array of lines that are parsed from a list of ingredients. It will:

  • Parse ingredient types from each line

  • Parse quantity values from each line for each ingredient type

  • Parse units of measure from each line for each ingredient type

  • Combine all this into an single object per line

  • Return a ‘validation error’ when any of the above is not possible.

The validation error tells me what entity it was that triggered the failure so that I can go update my personally maintained dictionary of known items. This is Heavily inspired by the Rust compiler.

Is that a bit more work than I’d like? Yes of course, but that’s also OK because it’s not like I’m entering several new recipes a day. It’s more like 3-4 a week, so I can handle the early need to build this intense repository of acceptable ingredients, quantities, etc.

Also, this is a program that can last me for the rest of my life, so I don’t mind the investment.

A bit more granular

The Validator has 3 responsibilities at the moment

  1. Find a quantity or produce an error if not plausible

  2. Find a unit of measure or produce an error if not plausible

  3. Find a known ingredient or produce an error if not plausible

There’s a bit more to it than that because I’m doing a bit ‘extra’ in my error handling. But other than that it’s not so bad. The result of these ingredient string parses is an array of JS objects that I can work with later on. I could even convert these into JSON if I liked so that I wouldn’t need to do the conversion so many times.

The longer-term goal over the life of the project is to add them into a DB.

The even longer-term goal is to utilize GPT to accept raw, un-modified recipe strings and generate formatted JS objects, so the Validator will eventually be out of a job.

Estimated Date of Completion

I still think I can get it mostly finished by around 1 April. I only need to combine the ingredients from the ingredients object, and then generate the markdown file in my Obsidian vault.

At that point, it’ll be all done! I’ll open source it after it’s finished and after I have some time to tidy up what I’ve done.

Previous
Previous

Playing with WebGL and Angular

Next
Next

Ingredients as Data