Instructions

This is an ECMAScript (JavaScript) programming assignment. Particularly, this task will assess your skills to:

Your task is to write code for the robot working at the reception's desk (the Roboceptionist).
This robot will receive booking enquiries from people and it will have to extract three pieces of information from them:

  1. The name of the person making the booking;
  2. The time of the booking;
  3. The number of people for the booked table.
A booking enquiry may contain one, two or all three of these pieces of information. For example:

How to complete the task

To complete this task, you must write the code for your solution in the function parseBookingEnquiry that you can find in the file solution/task1.js.
This function has an input argument: bookingEnquiry. This argument stores the string with the booking enquiry that you must parse to extract the necessary information (i.e. person's name, time and number of people).
This function must return an object literal with the following properties:

If you need to use additional global variables or functions you can do so by writing the code in the file solution/task1.js outside of the function parseBookingEnquiry.
Below is a list of links to JavaScript files with sample code (and instructions) that you can copy and paste in the parseBookingEnquiry function to learn how to use nlp-compromise or string functions.

Sample code

How to test your solution

To test your solution, after you write code in the function parseBookingEnquiry in the file solution/task1.js, save the file, open the file index.html, and click the button Run simulation in the Control panel.
This will invoke the function parseBookingEnquiry 100 times. Each iteration will call the function with a different random booking enquiry.
In the right Log panel you will be able to see the results of your parsing process. Incorrectly parsed enquiries will generate an error message marked in red.
At the end of the simulation, the left Control panel will display your current success rate.

Logging

If you want to log messages you can use the JavaScript console.log method to log messages in the browser's debug console or you can use the global function log provided for you to log your text message in the right Log console panel of the game interface.
For example, if you want to log the string 'Hello world' in the Log panel with the global function log you can write in your code:
log('Hello world')
If you want to log the string 'Hello world' in the browser's debug console instead, you can write in your code:
console.log('Hello world')

Hints

This assignment already includes references to use the library nlp-compromise taught during this unit. Using the functions offered by this library may be the more efficient way to extract the desired information from the booking enquiries (with less than ten lines of code!).
If you want to use nlp-compromise, try to look into the function match (documentation here) and look at how to use the default tags offered by nlp-compromise (you can find a list of the tags here, by scrolling down the page).
Alternatively, you may use the provided JavaScript string methods and regular expressions.

Marking criteria:

Category Weighting Result
Parsing success rate 2.75 marks The final mark for this category is computed using the following formula:
2.75 * (success rate / 100)
Quality of the code 0.5 marks 0 marks. The success rate is below 60% or the code is unnecessarily too long, it uses too many if conditional blocks or it uses string / nlp methods incorrectly. 0.5 marks. The success rate is above 60% and the code is short, simple to read, elegant, and it uses string / nlp methods correctly.