You're working for a flower marketing company and your job is to guess people's email addresses when given their full name and the domain name of the company they work for so you can send them coupons for holiday bouquets.
You've decided that instead of manually predicting their email addresses, you'll write a program to do it for you. This will allow you to watch your favorite actor John Cho crack jokes in the TV show Selfie.
Anyway...you have the following information available:
- The potential customer's name.
- The domain name of the company he/she works for.
- The names and emails of other advisors that work for the same company (and domain name).
The last bit of information is particularly helpful as it's what you use to figure out what pattern a company uses when assigning its email addresses.
Once you understand their pattern, you then make a prediction on what the advisor's email will be.
As an example, let's say you have a potential customer named "Jahmil Eady" who you know works for "wiser.com".
For this exercise, there are four potential patterns this employee's email could come in (or none at all):
Pattern | ||
---|---|---|
1 | first_name_dot_last_name | [email protected] |
2 | first_name_dot_last_initial | [email protected] |
3 | first_initial_dot_last_name | [email protected] |
4 | first_initial_dot_last_initial | [email protected] |
So, if you know the correct addresses for several other people who work at "wiser.com", you can predict Jahmil Eady's email address. For instance, if you know that Bianca Hoppe's email is [email protected]
, then you know that Wiser uses the first-initial-dot-last-name pattern, thus Jahmil Eady's email is probably [email protected]
.
Given the following sample dataset of past customers:
{
"Jahmil Eady": "[email protected]",
"Armando Amador": "[email protected]",
"Linda Li": "[email protected]",
"Anisha Ramnani": "[email protected]",
"Sergey Brin": "[email protected]",
"Nikki Thean": "[email protected]",
"Amanda Pickering": "[email protected]"
}
Create a program that will read a JSON file of known emails, much like the JSON above, and use this data to predict new email addresses.
To accomplish this lab, your program must be able to read JSON. So what is JSON? Well it stands for JavaScript Object Notation. JSON is a way to store information in an organized, easy-to-access manner. You might be alarmed and thinking, "But wait, I don't know JavaScript!" Don't worry, you don't need to know how to program in JavaScript to use JSON. In fact, Ruby has a built-in library for using it.
// government.json
{
"president": "Barack Obama",
"vice president": "Joe Biden",
"secretary of state": "John Kerry",
"secretary of the treasury": "Jacob Lew"
}
require 'open-uri'
require 'json'
gov_file = File.read('government.json')
gov = JSON.parse(gov_file)
gov
# =>
# {
# "president" => "Barack Obama",
# "vice president" => "Joe Biden",
# "secretary of state" => "John Kerry",
# "secretary of the treasury" => "Jacob Lew"
# }
To learn more about JSON, take a look at Copter Labs' post, Hack Hands' post, or Wikipedia's page.
This lab is test-driven so just run the testing suite to get started. The datasets you'll be reading are in spec/fixtures
.