From UBC Wiki

Authors: Emily Jia & Phoebe Wu

What is the problem?

Everyone has specific dietary restrictions whether they stem from allergies, health reasons, culture, or even just personal preferences.

We want to utilize Prolog's strength for Natural Language Processing to create a recipe recommender that suggests the user recipes based on their personal preferences, dietary restrictions, and time they have available to cook.

Some sample inquiries:

  • biscuits
  • gluten-free bread
  • vegan carrot cake
  • low carb pasta
  • some chocolate chip cookies that are paleo
  • an apple pie that doesn't have dairy
  • dumplings with no meat
  • brownies without nuts

What is the something extra?

Our database of recipes will be retrieved through an API, rather than being hardcoded into the program.

What did we learn from doing this?

NLP & Pattern Matching

This project allowed us to really utilize and explore pattern matching in Prolog. It showed us why Prolog is an excellent language for Natural Language Processing.

As we were building this project, we discovered how rigid Prolog's pattern matching truly is. While it allows us to build simple sentences easily, it complicated a few things later on.

Because each recipe could have multiple restrictions on it, for example, "vegan gluten-free no soy beef lasagna", we initially had difficulty parsing out and differentiating the different restrictions. The dietary restrictions needed to be parsed out separately to fetch different results from the API while beef had to stay with lasagna for the main query.

Furthermore, we found that minor syntactical differences would result in the input being parsed incorrectly. For example, "gluten free" vs "gluten-free" and "no gluten". To mitigate this, we created a function to standardize all these forms into one.

Lastly, Prolog returns more than a single truth when there are multiple available when we might not have needed all possible truths.

Compared to other ways of implementing NLP like through convolutional neural networks, we found Prolog to have less plasticity.


For our something extra, we decided to pull our database of recipes from an API. From this, we learned how to make HTTP requests in Prolog and convert them into JSON dicts. In order to actually access and present the data in a readable way, we also had to learn how to use and manipulate dicts in Prolog.

We also added a feature that allowed to the user to view a different recipe if they were not satisfied with the first result. To do this, we learned how to implement a global variable in Prolog that acted as the index for the JSON dict that increased every time the user wanted to view another recipe. As there were only 10 recipes per API return, the user would be prompted to make a different search once they reached the end of the list.

Link to code