Building a class for morse code decoder

Assignment Help Python Programming
Reference no: EM131945781

Assignment: Building a Morse Code Decoder with Python

1. Morse Code Interpreter

The Morse Code System

As we have seen in the first assignment, the current International Morse Code system encodes a range of characters, including the ISO basic Latin alphabets (A-Z), some additional Latin letter representing accents, the Arabic numerals (0-9), and a small set of punctuations and procedural signals (known as prosigns).

Each character is presented in Morse Code as an unique sequence of ‘dot' (.) and ‘dashes' (_). Figure 1 presents a subset of the characters represented in Morse Code.

907_International Morse Code representation.jpg
Figure 1: International Morse Code representation (letters and numerals)

Each character represented by the Morse Code system is separated by a single space, and each word (i.e. a combination of multiple characters) is separated by three spaces.

The following is an example that includes a punctuation character (the question mark) at the end of the Morse Code sequence. (Note that the punctuation is cosidered as a single word with a single character.)

1. S e n t e n c e : WHO AM I ?
2. Morse S e q u e n c e : . . . . . ._ . .

How Morse Code is represented in this assignment?

In this assignment, we are going to adopt the same set of representation for the Morse Code used in the first assignment based on the binary digits. The ‘dots' are represented by the digit 0 and the ‘dashes' are represented by the digit 1. As for the spaces, they are represented by the character ‘*'.

Note that our representation of Morse Code encodes the standard 26 letters (i.e. ‘A' to ‘Z) and the 10 numerals (i.e. ‘0' to ‘9'), with three additional punctuation characters (i.e. the period ‘.'; the comma ‘,'; and the question mark ‘?').

Table 1 defines the set of Morse Code representation used in this assignment.

Character

Morse Code

Character

Morse Code

Character

Morse Code

A
B
C
D
E
F
G
H
I
J
K
L
M

01
1000
1010
100
0
0010
110
0000
00
0111
101
0100
11

N
O
P
Q
R
S
T
U
V
W
X
Y
Z

10
111
0110
1101
010
000
1
001
0001
011
1001
1011
1100

0
1
2
3
4
5
6
7
8
9
.
,
?

11111
01111
00111
00011
00001
00000
10000
11000
11100
11110
010101
110011
001100

Table 1: Morse Code representation for this assignment (letters, numerals, and punctuations)

For the same example given earlier, our Morse code sequence should read as below:

1. S e n t e n c e : WHO AM I ?
2. Morse S e q u e n c e : 0 1 1 ∗ 0 0 0 0 ∗ 1 1 1 ∗ ∗ ∗ 0 1 ∗ 1 1 ∗ ∗ ∗ 0 0 ∗ ∗ ∗ 0 0 1 1 0 0

Also note that, we assume the Morse code sequences to be decoded in this assignment represent proper words and sentences in English. Each Morse code sequence should represent a sentence in English.

Task 1: Building a class for Morse Code decoder

In the first task, you are required to define a class that serves as the Morse Code decoder. This class should have one instance variable which is a dictionary structure that represents each of the Morse Code characters (presented in Table 1) as a string sequence of binary digits (0 and 1). This decoder class is used for decoding any Morse Code sequences.

The implementation of this decoder class should include the following three methods:

• init (self):

This is the constructor that is required for creating decoder instances. You should define and initialise the dictionary structure for the Morse Code representation (i.e. the instance variable) in the constructor.

• str (self):

Re-define this method to present the Morse code representation table (i.e. the dictionary structure) in a readable format. You should return a formatted string in this method.

• decode(self, morse_code_sequence):

This is the method that performs the decoding process. This method should accept a Morse Code sequence as the argument, and attempt to decode it. The decoded message should be returned as a string. (If you encountered an invalid character while decoding, return an error message instead of the partially decoded message.)

Note: The Morse Code sequence should terminate with one of the three punctuation characters, i.e. the period ‘.'; the comma ‘,'; and the question mark ‘?'.

You should name this class as "Decoder" and the Python file as StudentID_decoder.py.

Task 2: Building a class for analysing decoded characters

In this task, you are required to define a class for analysing the number of occurrences for each of the letters (i.e. ‘A' to ‘Z) and numerals (i.e. ‘0' to ‘9') from the decoded sequences. This class should have one instance variable which is a dictionary structure that is used for keeping track of the number of occurrences for each of the letters and numerals decoded by the Morse Code decoder in Task 1.

The implementation of this character analyser class should include the following three methods:

• init (self):

This is the constructor that is required for creating instances of this class. You should define and initialise the dictionary structure for characters (i.e. the instance variable) in the constructor.

• str (self):

Re-define this method to present the number of occurrences for each of the letters and numerals in a readable format. You should return a formatted string in this method.

• analyse_characters(self, decoded_sequence):

This is the method that performs the analysis on the decoded sequences at the character level. This method should accept a decoded sequence as the argument, and attempt to count the occurrences for each of the letters and numerals encountered in the given decoded sequence. The counts should be updated in the dictionary structure defined in the constructor.

Note: You should not consider the punctuation characters in this task as they will be handled in Task 4 below.

You should name this class as "CharacterAnalyser" and the corresponding Python file as StudentID_character.py.

Task 3: Building a class for analysing decoded words

In this task, you are required to define a class for analysing the number of occurrences for each of the English words from the decoded sequences. This class should have one instance variable which is a dictionary structure that is used for keeping track of the number of occurrences for each word decoded by the Morse Code decoder in Task 1.

The implementation of this word analyser class should include the following three methods:

• init (self):

This is the constructor that is required for creating instances of this class. You should define and initialise the dictionary structure for words (i.e. the instance variable) in the constructor.

• str (self):

Re-define this method to present the number of occurrences for each word in a readable format. You should return a formatted string in this method.

• analyse_words(self, decoded_sequence):

This is the method that performs the analysis on the decoded sequences at the word level. This method should accept a decoded sequence as the argument, and attempt to count the occurrences for each word encountered in the given decoded sequence. The counts should be updated in the dictionary structure defined in the constructor.

Note: Again, you should not consider the punctuation characters in this task as they will be handled in Task 4 below.

You should name this class as "WordAnalyser" and the Python file as StudentID_word.py.

Task 4: Building a class for analysing decoded sentences

Following Task 2 and Task 3, you are required to define a class in this task for analysing the number of occurrences for each type of English sentences from the decoded sequences. This class should have one instance variable which is a dictionary structure that is used for keeping track of the number of occurrences for each type of sentences decoded by the Morse Code decoder in Task 1.

The types of sentence that we are handling in this assignment include: clauses (indicated by the comma), complete sentences (indicated by the period), and questions (indicated by the question mark).

The implementation of this sentence analyser class should include the following three methods:

• init (self):

This is the constructor that is required for creating instances of this class. You should define and initialise the dictionary structure for sentence types (i.e. the instance variable) in the constructor.

• str (self):

Re-define this method to present the number of occurrences for each sentence type in a readable format. You should return a formatted string in this method.

• analyse_sentences(self, decoded_sequence):

This is the method that performs the analysis on the decoded sequences at the sentence level. This method should accept a decoded sequence as the argument, and attempt to count the occurrences for each sentence type (which could be a number of clauses and/or a full sentence or a question) encountered in the given decoded sequence. The counts should be updated in the dictionary structure defined in the constructor.

You should name this class as "SentenceAnalyser" and the corresponding Python file as StudentID_sentence.py.

Task 5: Putting all the classes together

In this final task, we will test all the classes defined above. You should define a function called main() that will drive the flow of execution of the program. Below is a sequence of tasks that should execute within the main() function.

• Create an instance for each of the four classes. You should have a decoder, a character analyser, a word analyser, and a sentence analyser.

• Prompt the user to input any random sequences of Morse Code. The Morse Code sequences can be of any length but with the minimum of one set of three consecutive ‘*'. (Note that the user should be allowed to input multiple Morse Code sequences not until the user indicates that he/she would like to terminate.)

• Invoke the corresponding method in the decoder to perform the decoding on each of the Morse Code sequences provided by the user. (All the decoded sequences should be displayed on the console.)

• Invoke the corresponding method in the character analyser to determine the total number of occurrences for each of the letters and numerals appeared in all the decoded sequences.

• Repeat the same task for the total number of occurrences for each word and each sentence type encountered in all the decoded sequences.

• Display all the analysis results on the console in a readable format.

Note: Some of the tasks above may be implemented as functions. You should make your own decision with respect to this. You should also consider designing a menu with options allowing the user to select which level of analysis is intended (character, word or sentence).

You should name the Python file of this task as StudentID_main.py.

Attachment:- Python-Assigignment.rar

Reference no: EM131945781

Questions Cloud

What is the price of a put option using the two period model : Binomial Option Pricing Model S = Asset Price = 88. What is the price of a put option using the two period model? Show all work.
What is the estimated value of bill inc common stock : Bill Inc. common stock is expected to pay a $2.32 dividend at the end of the year and is in a risk class that requires an 8.5% required return.
Prepare a report that shows the effect on the income : Prepare a report that shows the effect on the company's total net operating income of buying part F77 from the supplier
Analytical quantitative chemistry : Several Routine or newer sample pretreatment methods have been discusses for analytical quantitative chemistry
Building a class for morse code decoder : Building a class for Morse Code decoder. In the first task, you are required to define a class that serves as the Morse Code decoder.
Describe what is better for cleaning : Describe what is better for cleaning when a hard water is used, a soap or a detergent, and why?
Calculate the number of units sold : Calculate the number of units sold at which the owner of WalkRite would be indifferent between the original salary-plus-commissions plan
Calculate the monetary value for both the jobs : Bill Mason is considering two job offers. Job 1 pays a salary of $41,900 with $4,875 of nontaxable employee benefits. Job 2 pays a salary of $40,000 and $6,530.
Combustion of the hydrocarbons : What is the balance equation for complete combustion of the following hydrocarbons: a) butane b) cyclohexane

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd