Lab 1: Regular Expressions

Starter Code

Get the starter code on GitHub Classroom!

Docker

There’s a docker image available for this course. See the course docker instructions for details about how to work on your own machine.

RegEx Practice (15 pts)

Practice regular expressions by playing RegEx Golf.

You must complete the following: (14 points, autograded)

  • Warmup (2pts)

  • Anchors (2pts)

  • It never ends (2pts)

  • Ranges (2pts)

  • Backrefs (2pts)

  • One additional puzzle of your choosing (4pts + 1pt extra credit for each additional solution)

Turn In

In the file golf.py, fill in your best regular expression for each of the puzzles that you solved. (1 point for a file with any diff)

Integrity Note

Since these puzzles are online, there are (undoubtedly) solutions posted somewhere. Under the HMC honor code, I trust you to submit the best solutions you can come up with on your own.

SlackBot (35 PTS)

We’ll use Slack for communicating with each other this semester. There are already channels set up on our Slack Workspace for each of the assignments, and you should feel free to create your own channels for communicating with your teammates.

Stop now and make sure that you have access to the CS159 Slack Workspace.

For this part of lab, you will make an ELIZA-like chatbot that can join our slack workspace. You will follow these steps:

  1. Copy an available Bot User OAuth Token from the list of tokens posted on Slack in the Lab 1 channel at the start of class.

  2. Open the file slackbot.py and paste in your access token.

  3. Start your bot by running python3 slackbot.py. To see the bot in the Slack app, search for the username listed on the doc (on a Mac, command+K opens the search bar). Send a direct message to that bot in Slack, and confirm that it replies. (It should use the name and emoji you specify in your file.)

Once you have those steps working, you’re ready to improve upon your bot.

The only requirement is that you must modify the make_message function in slackbot.py to respond to messages from Slack users. Your function must make use of regular expressions using the Python re library. In particular, you should use each of the following at least once (3 points):

  • Regular expression groups ((...))

  • Character classes ([...], \d, \D, \w, \W, \s, \S, etc.)

  • Regular expression quantifiers (+, *, and/or {...})

You can choose the domain and personality of your both. It can be a Rogerian psychologist like ELIZA, or you can choose a different domain. If you choose a different domain, make sure it’s one where you can reasonably expect repetition, so regular expressions will be effective.

You should also update the name and emoji image of your chat bot! In Slack, if you click the icon to add an emoji to a message and then hover over the different emoji choices, it will tell you want the text alias for each emoji is. The default is the :dog: emoji.

Turn In

On Gradescope, you should submit your completed slackbot.py file with your implementation. (1 point for a file with any changes)

You should also submit a .pdf report that describes your Bot. That report should have the following sections:

  • Overview: An introduction to your SlackBot. What domain does it work in? What is its personality? (5 points for completeness and clarity)

  • Regex Description: Clearly describe how you make use of each of the required regular expression features in your make_message function. (5 points for completeness and clarity)

  • Analysis: Describe at least one interaction with your bot that worked well. You should include a screenshot of your discussion inside of Slack. Additionally, describe at least one interaction with your bot that works poorly (or not as one might expect). Thoughtfully describe how you would address the existing shortcomings of your bot if you had more time. For example, what would you do to make your bot better if you had another week to work on it? If you were going to use this code as the starting point for a final class project? (20 points for completeness and clarity)

You're welcome to write this up however you like, as long as it saves as a PDF. As one option, the starter code has a Markdown file that you can use to write your analysis. To turn your markdown into a .pdf file, use pandoc:

pandoc analysis.md -o analysis.pdf

If you need help getting pandoc running on your own machine, you can refer to the Docker instructions for a way to use Docker to do this. Please add your analysis.pdf file to your GitHub repository so that we can view it for grading. (1 point for having a nonempty analysis file)