Course:CPSC312-2021/Nutrition Planner

From UBC Wiki

Authors: George Yu, Stephen Li, Elton Kok

What is the problem?

When trying to hit fitness goals, one of the hardest problems is maintaining a diet and planning your meals. This app would help people log and plan their meals so they know how much of each macronutrient they have consumed in the day.

What is the something extra?

FoodData Central API

In class, we've seen many examples of programs with hard coded atoms in the knowledge base in order for the program to work. Initially, our idea was also to hard code atoms for the food in our knowledge base. However, we decided to try to use an API to get any type of food. In this way, our program allows for the dynamic entry of various foods. The user can search for any food they've eaten and our program will search the FDC API for the respective food and return its nutrition information.

Dynamic Predicates

In a nutrition planner, the nutrition data should change based off what the user inputs into the program. We knew our program would have to handle user input and create dynamic predicates to update nutrition information. To achieve this, we used assert, and retract to add and change atoms in our knowledge base. Through this, we were able to have the state of the program change based on user input.

Subject to change, but one of the ideas is to make suggestions on food based on the current meals that are in the planner.

What did we learn from doing this?

Although Prolog supports API requests and JSON parsing, it was quite challenging to work with as there was no way to iterate over the JSON data that was returned from the FoodData Central API. However, it was still possible and the implementation works perfectly fine. Prolog works great with input based programs like ours. We found it was rather simple to use its pattern matching in order to determine which predicates to run. It was also very simple to determine what inputs are valid or not in an input based program for Prolog.

Backtracking in Prolog is helpful in a lot of situations. However, in our program, we wanted a linear flow and not have any weird retries. We learned how to use the cut operator ! in Prolog to prevent backtracking in places where it wouldn't make sense to. Through the usage of the cut operator, we were able to achieve a linear flow of the program.

(This should be written after you have done the work.)What is the bottom-line? Is functional programming suitable for (part-of) the task? Make sure you include the evidence for your claims.

Links to code etc