Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You must provide definitions for a contacts directory ( mirroring the video rental database type presented in class ) such that rows are list of
You must provide definitions for a contacts directory mirroring the video rental database type presented in class such that "rows" are list of tuples with the first element being a last name, the second element an email address, and the third element a Metaphone code.
Each "column" will be a string, and the snippet below can be used as a starting point:
type Char
type Char
type Char
type Row
type Database Row
You must create a function named "returnSampleData" that takes no arguments and, when called, returns a sample database of tuples ieCharChar with at least entries including yourself that contain both a last name and an email address; The type definition for this function is provided below:
returnSampleData :: CharChar
You must create a function that will transform an argument list of tuples of strings into a return database of tuples, by calling your metaphone code generating function described below on each row. It should thus transform the return value of your returnSampleData function above into an instance of the Database type mentioned on the previous page. This function must use a list comprehension to achieve this conversion. The type definition for
this function is provided below:
convertDatabase :: CharChar Database
You must design and implement a series of functions that will be called in sequence by another function you will write to generate a simplified Metaphone code according to therules provided on the following page. Please note that these rules represent a simplified
variation on the Metaphone code and not the actual Metaphone code published described in
"Hanging on the Metaphone", Lawrence Philips. Computer Language, Vol. No
Please note that there are several constraints on these rules that absolutely must
be observed, so read this specification very carefully and thoroughly.
Finally, you must include a single "query" function implemented using a list comprehension that, when called with a database of tuples as the first argument and a string "search target" as the second argument returns all of the records in the database associated with a Metaphone code that matches the Metaphone code that would be generated for the second argument.
Listed below are the Metaphone transformation "rules" that you must implement. Please note the following constraints that must be observed:
No indexing operators are permitted, not even ones you write yourself.
No length function is permitted, not even one you write yourself.
Only the provided selector functions head', tail', last', and init' are permitted
No concatenation is permitted, so you must use the list construct:or : instead Every function must be recursive EXCEPT for the implementations of Rules and
No recursive helper functions are permitted EXCEPT for the implementation of Rule
Rule Description:
Remove all adjacent duplicate letters except the letter C
If the argument begins with KNGNPNAE or WR then drop the first letter.
nb This function will not be recursive.
If the argument ends with an MB the drop the last letter ie drop the B
nb This function will not be recursive.
If an instance of C is followed by IA or H then it must be changed to an X but if an instance of C is followed by IE or Y then it must be changed to an S Every other instance of the letter C must be changed into K
If an instance of D is followed by GEGY or GI then it must be changed to a J Every other instance of the letter D must be changed into T
If an instance of G is followed by an H or an N then it must be removed, but if an instance of G is followed by IE or Y then it must be changed to a J Every other instance of the letter G must be changed into K
Remove every instance of H that appears after a vowel but not before a vowel.
Transform every instance of CK into an instance of K
nb This function has been provided for you as an example, on the following page.
Transform every instance of PH into an instance of F
Transform every instance of Q into an instance of K
If an instance of S is followed by HIA or IO then it must be changed to an X
If an instance of T is followed by IA or IO then it must be changed to an X
Transform every instance of V into an instance of F
Transform every instance of X into the sequence KS
Transform every instance of Z into an instance of S
Remove every instance of a vowel or Y unless it appears at the very beginning.
nb This function will require a recursive "helper function", so that the replacement is considered for every character except the first character.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started