Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Python Expert

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

Python, Programming

  • Category:- Python
  • Reference No.:- M92784437

Have any Question?


Related Questions in Python

Show times in tmus and seconds1 an associate grasps an oven

Show times in TMUs and seconds. 1. An associate grasps an oven door within reach and pulls it open 18 inches with the left hand (he does not relinquish control of the door). With a pan in the right hand, he carefully pos ...

Question why is software configuration management

Question : Why is software configuration management considered an umbrella activity in software engineering? Please include examples and supporting discussion. The response must be typed, single spaced, must be in times ...

Assignment1 utilising python 3 build the following

Assignment 1. Utilising Python 3 Build the following regression models: - Decision Tree - Gradient Boosted Tree - Linear regression 2. Select a dataset (other than the example dataset given in section 3) and apply the De ...

A software company sells a package that retails for 99

A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10 - 19 20% 20 - 49 30% 50 - 99 40% 100 or more 50% Write a program using python t ...

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Questionwhat is a python development frameworkgive 3

Question What is a python development framework? Give 3 examples python development framework used today. and explain which development framework is used in which industry.

In this programming assignment you will write a client

In this programming assignment, you will write a client pingprogram in Python. Your client will send a simple ping message to a server, receive a correspondingpong message back from the server, and determine the delay be ...

Simple python traffic lightswrite a program that simulates

Simple Python (Traffic lights) Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on, and onl ...

Sieve of eratosthenes in pythonthe goal is to find all the

Sieve of Eratosthenes (in Python) The goal is to find all the prime numbers less than or equal to some natural number maxn. We have a list that tells us if any of the numbers 0..maxn are "marked". It can be an array of b ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As