QuestionQuestion

Transcribed TextTranscribed Text

Learning Braille For this assignment, you’ll need to learn some basic Braille. To start, watch this video on the basics of English Braille In Braille, characters are represented by cells. A cell generally represents one letter. A cell contains six (or sometimes eight) positions for dots, in two columns. At each position, there could be a raised (shaded) dot, or left flat (empty). French Braille All Braille systems are organized into decades: ordered groups of 10 letters. Each position in the decade has an associated pattern. See the YouTube video for more on the patterns and a mnemonic for memorizing them. English Braille has two and a half decades for its letters, French has four. When Braille was developed in the 19th century, the letter ‘w’ was not commonly used in French. This is why ‘w’ is not where you’d expect it in the alphabet in either system. The 40 letters make up a table of four rows and ten columns. We will be counting from zero for the rows and columns, since Python and other programming languages work this way. 0 1 2 3 4 5 6 7 8 9 0 r r r r r r r r r r r r r r r r r r r r r r r r r a / 1 b / 2 c / 3 d / 4 e / 5 f / 6 g / 7 h / 8 i / 9 j / 0 1 r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r k l m n o p q r s t 2 r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r u v x y z ¸c ´e `a `e `u 3 r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r ˆa ˆe ˆı ˆo ˆu ¨e ¨ı ¨u œ w Decade 0 is also used to represent the digits 1-9 and 0, in that order. So 1 is the same as ‘a’, etc. Finally, there is another decade to represent the most common punctuation, where we take the decade-pattern and shift it all downward. Note the most common punctuation in French Braille is different from English Braille (in the video). 0 1 2 3 4 5 6 7 8 9 4 r r r r r r r r r r r r r r r r r r r r r r r r r , ; : . ? ! ” ( * ) Finally, for this assignment, there are six more important characters in French to know about which do not follow the decade pattern. Note the capital symbol in French Braille is different from the English Braille one in the video. r r r r r r r r r r r r r space hyphen/dash apostrophe guillemets capital number 3 1 Warmup [0 points] For us to be converting text to Braille, we’ll need a few helper functions. Download helpers.py, put your name at the top, and complete these functions: 1. is in decade: given two strings, determine if the first one is contained in the second one, and that the first string is a single character. This will be useful in the future where we are checking if a character is part of a given decade. 2. is irregular: given a string, determine if it’s a single character that is one of the irregular characters listed in the pre-defined global variable IRREGULAR CHARS. These “irregular” characters are called as such because they don’t follow regular patterns like the other Braille characters we’ll see. This will only return True if it’s a single character, so “- -” would return False. 3. is digit: given a string, determine if it’s a single character representing a digit (0-9). We provide the global variable DIGITS. 4. is punctuation: given a string, determine if it’s a single character that is one of the punctuation marks that follow the regular Braille patterns. These have been pre-defined for you in the global variable PUNCTUATION. Then have a look at the function is letter we provided. It tests whether a string is a single character that is one of the regular French Braille letters. You should not edit this function. It is provided for you to call this function elsewhere. Then complete: 5. is known character: given a string, determine if it’s a single character representing one of the letters, digits or punctuation supported by our Braille translator. 6. is capitalized: return whether a string is a single capitalized letter supported by our Braille translator. 4 2 Single Characters to French Braille [30 points] In this assignment we’ll be converting four types of characters to Braille: letters (A-Z & a-z), digits (0-9), regular punctuation, and irregular characters. You may want to review page 3 for this. Download char to braille.py and put your name at the top. Complete this function: 1. convert irregular [5 points]: given a character that is one of the irregular characters, return it in French Braille. We’ll be using o to represent a raised dot and . to represent an empty position, and putting a new line in between each row of the Braille cell. A hyphen hence becomes: .. .. oo Return None if the input is not an irregular character. Note: there are multiple characters that correspond to apostrophe and hyphen (see docstring). Then take a moment to note the function decade pattern, which gives the pattern associated with each column of the Braille decades. A “pattern” is the set of what dots are raised in the top two rows of the 0th decade. You should not edit this function. It is provided for you to call elsewhere. Then, complete: 2. convert digit [5 points]: given a string representing a digit, convert it to Braille. Return None if the string is not a digit. 3. convert punctuation [5 points]: given a string representing one of the regular forms of punctuation, convert it to French Braille. Return None if the string is not one of the standard punctuation in PUNCTUATION. 4. decade ending [5 points]: return the associated bottom row for a given decade, from the table on page 3. (0: ‘..’, 1: ‘o.’, 2: ‘oo’, 3: ‘.o’) Then read the docstrings of these two functions that we give you. Do not edit these functions; they are provided for you to call elsewhere. • letter row given a letter, returns which of the four letter decades it belongs to (zero-indexed). See the table on page 3. • letter col given a letter, returns its position (zero-indexed) within its decade. See the table on page 3. Then complete: 5. convert letter [5 points]: given a letter (upper or lower case), convert it to French Braille. Return None if it is not a letter in French Braille. 6. char to braille [5 points]: given a character, convert it to French Braille if we know how. If it’s a letter we don’t support, return the letter unchanged. 5 3 Converting Braille Representations Text can be represented, or encoded in many different ways. Our goal in this part of the assignment is to convert from how we have been representing braille characters so far into Unicode, which is how we represent text on most of the Internet. 3.1 Different representations In this assignment, we will use five ways to represent a letter such as r r r r (n). 1. The o-string representation. This is what we’ve been using so far, where we represent a raised dot with an o and a lowered with a ., and new line characters to indicate new rows of the braille cell. So r r r r is: oo .o o. 2. The raised-position representation. Every position in a braille cell has a standardized number. The positions are numbered as such: We can then list how many of the positions have a raised dot. For r r r r that would be 1, 4, 5, and 3; or, the string ‘1453’. Traditionally, braille uses six dots, which is what we have been working with so far. However for academic/mathematical notation an eight-dot system is often used to expand the range of possible symbols. 3. The binary representation. Based on the position numbers above, if we have a raised dot we place a 1; if lowered, 0. So ‘1453’ becomes ‘10111000’. For this we will always use an 8-bit representation. This is because Unicode represents 8-dot braille cells rather than the tradional 6-dot cells. To turn a 6-dot cell into an 8-dot cell, add two unraised dots to the end. 4. The hex representation. This is a hexadecimal number that corresponds to the Unicode representation (see below), such as 281316 for h ( r r r ). 5. The Unicode representation. Unicode is the most popular way of encoding text on computers today. It also supports 8-dot Braille. Each character in Unicode has an associated hexadecimal number, whether it’s ‘n’ (014416), ‘n’ (092816) or the heart emoji (276416). For us to go from o-string to Unicode, we will convert in multiple stages: o-string → raised-pos → binary → hex → Unicode 6 3.2 Code to Complete [20 points] Download the file to unicode.py and put your name at the top. Complete these functions: 1. raisedpos to binary [5 points]: convert a string in raised-position format to binary format (see previous page). Do not worry about handling strings that are not in raised-position format. 2. binary to hex [5 points]: convert a binary representation of a Braille character to its unique hex number. See the docstring for how. Note: this will require the built-in function hex, which takes in a base-10 number and converts it to a string in hexadecimal that starts with ‘0x’. For example, hex(26) returns the string ‘0x1a’ rather than just ‘1a’. 3. is ostring [5 points]: return whether the input string is formatted like a Braille o-string. Both 6-dot and 8-dot o-strings should return True. 4. ostring to unicode [5 points]: if we have an o-string, using the functions in the to unicode module, convert from o-string to Unicode. Otherwise, return the string unchanged. Remember we wrote some functions in this module for you to use.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

from text_to_braille import *

ENG_CAPITAL = '..\n..\n.o'
# You may want to define more global variables here

####################################################
# Here are two helper functions to help you get started

def two_letter_contractions(text):
    '''(str) -> str
    Process English text so that the two-letter contractions are changed
    to the appropriate French accented letter, so that when this is run
    through the French Braille translator we get English Braille.
    Provided to students. You should not edit it.

    >>> two_letter_contractions('chat')
    'âat'
    >>> two_letter_contractions('shed')
    'îë'
    >>> two_letter_contractions('shied')
    'îië'
    >>> two_letter_contractions('showed the neighbourhood where')
    'îœë ôe neiêbürhood ûïe'
    >>> two_letter_contractions('SHED')
    'ÎË'
    >>> two_letter_contractions('ShOwEd tHE NEIGHBOURHOOD Where')
    'ÎŒË tHE NEIÊBÜRHOOD Ûïe'
    '''
    combos = ['ch', 'gh', 'sh', 'th', 'wh', 'ed', 'er', 'ou', 'ow']
    for i, c in enumerate(combos):
       text = text.replace(c, LETTERS[-1][i])
    for i, c in enumerate(combos):
       text = text.replace(c.upper(), LETTERS[-1][i].upper())
    for i, c in enumerate(combos):
       text = text.replace(c.capitalize(), LETTERS[-1][i].upper())

    return text


def whole_word_contractions(text):
    '''(str) -> str
    Process English text so that the full-word contractions are changed
    to the appropriate French accented letter, so that when this is run
    through the French Braille translator we get English Braille.

    If the full-word contraction appears within a word,
    contract it. (e.g. 'and' in 'sand')

    Provided to students. You should not edit this function.

    >>> whole_word_contractions('with')
    'ù'
    >>> whole_word_contractions('for the cat with the purr and the meow')
    'é à cat ù à purr ç à meow'
    >>> whole_word_contractions('With')
    'Ù'
    >>> whole_word_contractions('WITH')
    'Ù'
    >>> whole_word_contractions('wiTH')
    'wiTH'
    >>> whole_word_contractions('FOR thE Cat WITh THE purr And The meow')
    'É thE Cat WITh À purr Ç À meow'
    >>> whole_word_contractions('aforewith parenthetical sand')
    'aéeù parenàtical sç'
    >>> whole_word_contractions('wither')
    'ùer'
    '''
    # putting 'with' first so wither becomes with-er not wi-the-r
    words = ['with', 'and', 'for', 'the']
    fr_equivs = ['ù', 'ç', 'é', 'à', ]
    # lower case
    for i, w in enumerate(words):
       text = text.replace(w, fr_equivs[i])
    for i, w in enumerate(words):
       text = text.replace(w.upper(), fr_equivs[i].upper())
    for i, w in enumerate(words):
       text = text.replace(w.capitalize(), fr_equivs[i].upper())
    return text



####################################################
# These two incomplete helper functions are to help you get started

def convert_contractions(text):
    '''(str) -> str
    Convert English text so that both whole-word contractions
    and two-letter contractions are changed to the appropriate
    French accented letter, so that when this is run
    through the French Braille translator we get English Braille.

    Refer to the docstrings for whole_word_contractions and
    two_letter_contractions for more info.

    >>> convert_contractions('with')
    'ù'
    >>> convert_contractions('for the cat with the purr and the meow')
    'é à cat ù à purr ç à meœ'
    >>> convert_contractions('chat')
    'âat'
    >>> convert_contractions('wither')
    'ùï'
    >>> convert_contractions('aforewith parenthetical sand')
    'aéeù parenàtical sç'
    >>> convert_contractions('Showed The Neighbourhood Where')
    'Îœë À Neiêbürhood Ûïe'
    '''
    # ADD CODE HERE
    combos = ['ch', 'gh', 'sh', 'th', 'wh', 'ed', 'er', 'ou', 'ow']
    words = ['with', 'and', 'for', 'the']
   
   
    converted_text = text

    for word in words:
       converted_text = converted_text.replace(word, whole_word_contractions(word))
       converted_text = converted_text.replace(word.capitalize(), whole_word_contractions(word.capitalize()))
       converted_text = converted_text.replace(word.upper(), whole_word_contractions(word.upper()))            
            
    for comb in combos:
       converted_text = converted_text.replace(comb, two_letter_contractions(comb))
       converted_text = converted_text.replace(comb.capitalize(), two_letter_contractions(comb.capitalize()))
       converted_text = converted_text.replace(comb.upper(), two_letter_contractions(comb.upper()))
      

      
    return converted_text...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$35.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats