A parser for recipe ingredients.
This project provides a parser that can be used when attempting to parse ingredients of a recipe.
The general approach is to define a set of templates for ingredients and try to parse a raw ingredient according to that template.
For example, a template could be {amount} {unit} {form} {ingredient}
which would match raw ingredient strings such as:
- 2 cups grated cheese
- 4 grams chopped onion
Following the instructions below to build and run the project in a local development environment.
After cloning the source code to a destination of your choice, run the following command to build the project:
dotnet build
The test suite can be run using the following command:
dotnet test
To create an IngredientParser
instance a builder interface is provided. The default configuration is intended to support a wide range of ingredient formats.
The builder can be used to customise the parser as required. For more details on customising the parser, refer to the docs.
var parser = IngredientParser
.Builder
.New
.WithDefaultConfiguration()
.Build();
From here, the TryParseIngredient
method can be used to parse an ingredient string.
if (parser.TryParseIngredient("2 cups grated cheese", out ParseResult parseResult))
{
// Use parsed result
...
}
An example console application is provided that can be used to test the parser out. Run the following command to start the example:
dotnet run --project RecipeIngredientParser.Example