Answered step by step
Verified Expert Solution
Link Copied!

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 3-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 2-tuples (i.e.,[([Char],[Char])] with at least 10 entries (including yourself) that contain both a last name and an email address; The type definition for this function is provided below:
returnSampleData :: [([Char],[Char])]
You must create a function that will transform an argument list of 2-tuples of strings into a return database of 3-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 :: [([Char],[Char])]-> 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. 7, No.12,1990).
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 3-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 permitted2.
No concatenation ('++') is permitted, so you must use the list construct:or (':') instead Every function must be recursive EXCEPT for the implementations of Rules 2 and 3
No recursive helper functions are permitted EXCEPT for the implementation of Rule 16
Rule Description:
1. Remove all adjacent duplicate letters except the letter 'C'.
2. If the argument begins with 'KN','GN','PN','AE', or 'WR', then drop the first letter.
(n.b., This function will not be recursive.)
3. If the argument ends with an 'MB', the drop the last letter (i.e., drop the 'B').
(n.b., This function will not be recursive.)
4. 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 'I','E', or 'Y', then it must be changed to an 'S'. Every other instance of the letter 'C' must be changed into 'K'.
5.If an instance of 'D' is followed by 'GE','GY', or 'GI', then it must be changed to a 'J'. Every other instance of the letter 'D' must be changed into 'T'.
6. 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 'I','E', or 'Y', then it must be changed to a 'J'. Every other instance of the letter 'G' must be changed into 'K'.
7. Remove every instance of 'H' that appears after a vowel but not before a vowel.
8. Transform every instance of 'CK' into an instance of 'K'.
(n.b., This function has been provided for you as an example, on the following page.)
9. Transform every instance of 'PH' into an instance of 'F'.
10.Transform every instance of 'Q' into an instance of 'K'.
11. If an instance of 'S' is followed by 'H','IA', or 'IO', then it must be changed to an 'X'.
12. If an instance of 'T' is followed by 'IA' or 'IO', then it must be changed to an 'X'.
13. Transform every instance of 'V' into an instance of 'F'.
14. Transform every instance of 'X' into the sequence 'KS'.
15.Transform every instance of 'Z' into an instance of 'S'.
16. Remove every instance of a vowel or 'Y' unless it appears at the very beginning.
(n.b., 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

More Books

Students also viewed these Databases questions

Question

Explain the importance of nonverbal messages.

Answered: 1 week ago

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

Prepare an employment application.

Answered: 1 week ago