From UBC Wiki


Authors: Justin Oh, Kayla Curtis, Katharine Cavers

What is the problem?

We want to investigate both natural language processing and web services in Prolog. Looking for a restaurant is a daily routine for many people. Our program will allow users to input a French or English sentence such as "Find me two inexpensive restaurants near UBC" and receive a list of restaurants matching their query. Behind the scenes, we will build a query based on the input they provide, call the Yelp REST API to find the answers, parse the JSON response, and return to the user a nicely formatted answer.

What is the something extra?

What did we learn from doing this?

We used (given in class) as a guide in creating our natural language processing. However, quickly our code grew significantly from this. Prolog was well suited to the task of natural language processing, as expressing sentence syntax was relatively simple to define. Using difference lists made parsing the input based on different syntactical pieces (e.g. a noun phrase, a location phrase) easier. Through processing of the user's input, we were able to construct a list of parameters to be used in our query to Yelp's API based on determiners (number of results desired), adjectives (type of cuisine, rating of the restaurant, price point), and location in the user's sentence. In this way, we were able to essentially translate an English/French sentence into an equivalent Yelp API query url.

Through the use of libraries, making the rest request was not too difficult - this can be seen in the make_request method in As well, parsing the JSON response was not too difficult either. The problem was essentially simplified to searching for a key=value pair in a list of key=value pairs. The HTTP and JSON code was much shorter than that we have written previously in languages such as Java; the code is significantly more succinct.

Overall, Prolog was very well suited to NLP and web service problems. Once we had a base for the NLP section, adding more adjectives and constraints was quite simple. Similarly, processing a REST request and response was relatively painless, and flexible in the types of results we wanted to return.

The main thing that we learned was writing large prolog programs, and changing our way of thinking to match it's declarative style. Prolog is extremely different from imperative programming, even more so than functional programming was. The idea of writing rules and facts, versus methods that take some input and return some output, took getting used to, but once we became comfortable, it felt quite natural. One of the first big challenges was figuring out how to compile and pass a list of query parameters through the different NLP syntax pieces, but embracing the idea of declarative/logic programming allowed us to do so by including a term in our rules for the resulting parameter(s).

Links to code etc