Course:CPSC312-2021/Yelp Search Engine

From UBC Wiki

Yelp Search Engine

Authors: Perry Liao, Yiyi Liu, Cynthia Zhou

What is the problem?

Using Prolog, can we use the Yelp API to recommend a restaurant to satisfy users' hunger? We seek to explore how we can break down user inputs to create a restaurant-centric search engine that can query an external database to give live feedback.

What is the something extra?

We'll be implementing a "I'm feeling lucky" system where the program will keep track of user's search queries and responses to learn their preferences, and to produce a restaurant recommendation suitable for the user. We'll be doing this by capturing the data on file. The user will also have the option of clearing the cached data anytime.

What did we learn from doing this?

Using an external API for our knowledge base


  • There are plenty of resources online. HTTP/JSON libraries are very straightforward.
  • The knowledge base is dynamic and it is constantly updated and maintained.
  • We do not need to internally store large amounts of data.


  • There can be inconsistencies with external databases. E.g., in the JSON responses, the key "price" doesn't exist on every item.
  • The project is not very scalable because of the API limit.
  • Since our project depends on a third party resource -- Yelp, it cannot guarantee 100% up time. Our project item definitions also have to match those of the Yelp API, so we are limited to the third-party database's specifications.
  • Our project depends on the internet so it won't be as efficient as locally defined knowledge base.

Saving persistent data using Prolog

We have to keep track of a lot of data. We've tried to create a global variable (e.g., a dictionary) to store the data that we want. But to initialize a dictionary and store the data in it is not really achievable. It was also very difficult to pass the same variables to every function call, since Prolog only has access to variables that are defined in the parameters. However, Prolog has a decent way of reading from and writing files to the disk. So we ended up keeping the persistent data in disk.

Is Prolog suitable for the problem?


  • We are easily able to capture keywords from the user query to build a query from a natural English sentence.
  • The code base would be smaller in comparison with the same program written in other languages, since Prolog is able to tackle this problem very effectively.
  • The code is scalable. There's very little coupling in our program so it's pretty easy to add more features.


  • The sentences need to be structured in a specific way because our program is not flexible enough to capture all possible sentences.

Prolog is quite suitable for searching engine problems like this. However, if we want to capture more diverse sentence structures we would have to be more elaborate in our declarations, such as including a modifying phrase. But, to keep the scope of our project straightforward and doable within with our individual schedules, we have chosen to write a search engine that expects the use to input sentences in a specific format.


Overall, our program does what we have expected. The code is simple and small. The user interacting with this program will be able to retrieve and find a restaurant matching their tastes. In the process of writing the project, we have encountered a few difficulties due to the lack a detailed debugger that other languages have access to. We had to modify `` quite a few times due to bugs that arose from having to parse different keywords of the query. If we were to continue building this program, we will add a way to give visual feedback to the users, such as a GUI. Currently, we are limited in how we can present the results to users.

Prolog on its own is quite limited. We think Prolog is best used as a backend that can be connected from an external application such as a web page built in JavaScript. This way, we can address the weakness of Prolog by providing a more intuitive way for users to use and receive results, while keeping the all the advantages that Prolog offers.

Links to code etc