Braille Text Analysis

Students will use string manipulations, turtles, lists, and dictionaries to collect and analyze braille text.

Overview

This assignment should be done as individual work. Be sure the work is your own.

  • Do not seek out solutions online, but do look online for how to use the Python commands you need. Stick to commands we've covered in class.
  • Do ask for help from me or our preceptors.
  • Do talk about solutions in general with classmates, and get minor debugging help from classmates. Do not work out whole programs with classmates or friends.
  • Do write down any people or websites where you get some measure of help.

For this assignment, you are expected to include a summary descriptive comment for each function or script you write. You will lose 1 point per function if you leave the summary comment out. If you're not sure what I want: ask me! I am providing you with a test file for testing the functions you write. Read it carefully.

Learning Goals

  1. Develop proficiency in handling text files by applying various techniques for file reading and writing.
  2. Refine string manipulation skills by implementing string operations to extract and modify information from files.
  3. Gain expertise in using the turtle graphics library to create interactive visual displays of information.
  4. Master the creation and manipulation of lists, a fundamental data structure in Python, to store and organize information.
  5. Acquire proficiency in working with dictionaries, another essential data structure, to efficiently collect and retrieve information in a structured manner.
  6. Apply the aforementioned skills to collect and display information from files using Python programming.

Preparing and handing in the assignment

Be sure that each function you write is preceded by a hash-marked comment that indicates the problem number, and inside it a triple-quoted comment that describes the function's purpose and its inputs and outputs.

Any non-code answers may be included in a Python file as either triple-quoted strings or comments.

Any script elements that you want to test your programs should be placed at the bottom of the file, inside the if __name__ == '__main__'conditional.

Braille Background

Braille is a tactile writing system used by people with visual impairment. It is traditionally written with embossed paper. Today, people typically use a braille writer, such as a portable braille notetaker or computer that prints with a braille embosser. As for reading computer screens, braille users have the option of using refreshable braille displays. What makes it refreshable is whenever the user moves their cursor through keyboard or voice commands, the display updates the dots in the braille cells.

The Importance of Building for All

  • An estimated 1 Billion people report to have a disability. (source: World Health Organization)
  • 85% of adults use the Internet (source: Pew Research Center)
  • Proving technology’s prevalence in modern-day society
  • Websites, mobile apps, common Internet usage becomes inaccessible to people with disabilities, preventing a large portion of society to gain knowledge of important services and information
  • 2021 survey claimed that in 2000 websites, 98% of them are not accessible (WebAIM)

Learn Python and be part of the change on making technology more accessible!

Additional Braille info

Getting Started with the Assignment

You will need to complete the following tasks that are labeled as TODO in the given code file:

  1. translator()
  2. upgrade braille to grade 1 to grade 2 braille
  3. draw_braille_character()
  4. addCommon()
  1. (_ pts) translator(): Define a function called translator that takes two input parameters, a string and the braille_dictionary. The string should be a normal English sentence that is readable by humans. The dictionary should be the one described above.

    The function should first use the split() function to divide the string into a list of words, it should then iterate through the list of words. If the word is contained in the dictionary (e.g. the Grade 2 Braille words), it should substitute it with the associated Braille character. If the word is not in the dictionary, you should iterate through the word string, character by character. It should find each character in the dictionary and replace it with the substituted braille character in a new list (each original character is the key and the replacement braille character is the value associated with that key in the dictionary). Anything that is not contained in the dictionary (e.g. punctuation marks), should be ignored. The function should return a nested list of Braille characters, with raised dots represented as 1's and flat dots represented as 0's. For example, the function should print the nested list below when given this call:

    braille_string = translator(“Hi!”, braille_dictionary)
    print(braille_string)
    ---------------------------------------------------
    [[1,1,0,0,1,0], [0,1,0,1,0,0]]

  2. (_ pts) draw_braille_character():I've given you the skeleton of a function called draw_braille_character that takes one parameter, a list of 0's and 1's corresponding to a Braille character. The function currently iterates through the list and uses a turtle to draw six circles corresponding to the six circles in a Braille character. Update the function to fill in the appropriate circles depending on the input. The raised dots should be represented by filled-in circles and the flat dots should be represented as empty circles.
  3. (_ pts) addCommon()

    You are given a braille dictionary with numbers 1-9, the alphabet, the words but, can, do, every, from, go, have, just, knowledge, like, more, not, people, quite, rather, so, that, us, very, it, you, as, will. Convert the English to braille, grade 2 representations. Refer online for examples and cite any outside source used. Here is an example:
    In Grade 1 Braille:
    b e c a u s e In Grade 2 Braille:
    b (contraction for "be") c (contraction for "cause") In Grade 1 Braille, each letter of the word "because" is represented individually with its corresponding Braille cell. However, in Grade 2 Braille, the word "because" is contracted to a shorter form. The letter "e" is omitted, and the contraction "be" and "cause" are used instead. Here's another example for the word "can't": In Grade 1 Braille:
    c a n ' t In Grade 2 Braille:
    c (contraction for "can") ' (contraction for "not") t -- NOTE: There is a testing function in hw4Tests.py. Use it to check your work.

Helper Functions

You can use the helper function print_braille that will format the returned nested list as braille to the console. See below for an example:

braille_string = translator(“Hello, world!”, braille_dictionary)
print(braille_string)
---------------------------------------------------
1 0 1 0 1 0 1 0 1 0 0 0 0 1 1 0 1 0 1 0 1 1
1 1 0 1 1 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 0 1
0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 0 1 0 1 0 0 0

There is a testing function in hw4Tests.py. Use it to check your work.

draw_word() is also provided for you to help gain an understanding on drawing text to the screen using the turtle library. Read more on the turtle documentation online if you are stuck.

What you need to turn in

  • hw4Code.py file for this part of the assignment with a confirmation that your program will work with the test function.
  • .py file for this part of the assignment with a confirmation that your program will work with several text sentences of different lengths (1 sentence, 3 sentences, 1 paragraph).
  • Note:
    • Be sure that each function you write is preceded by a hash-marked comment (# comment) that indicates the problem number, and inside it a triple-quoted comment that describes the function’s purpose and its inputs and outputs.
    • Any non-code answers may be included in a Python file as either triple-quoted strings or comments.
    • Any script elements that you want to test your programs should be placed at the bottom of the file, inside the if __name__ == ‘__main__’ conditional.
    • Refer to the Python documentation if this does not make sense.

Test Case Explanation

Consider the following test case:

s1 = "the quick brown fox jumps over the lazy dog"
print(s1)
print(translator(s1, braille_dictionary))
print()
assert translator(s1, braille_dictionary) == [[[0, 1, 1, 1, 1, 0], [1, 1, 0, 0, 1, 0], [1, 0, 0, 0, 1, 0]], [[1, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1], [0, 1, 0, 1, 0, 0], [1, 0, 0, 1, 0, 0], [1, 0, 1, 0, 0, 0]], [[1, 1, 0, 0, 0, 0], [1, 1, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 1, 1], [1, 0, 1, 1, 1, 0]], [[1, 1, 0, 1, 0, 0], [1, 0, 1, 0, 1, 0], [1, 0, 1, 1, 0, 1]], [[0, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1], [1, 0, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 0, 0]], [[1, 0, 1, 0, 1, 0], [1, 1, 1, 0, 0, 1], [1, 0, 0, 0, 1, 0], [1, 1, 1, 0, 1, 0]], [[0, 1, 1, 1, 1, 0], [1, 1, 0, 0, 1, 0], [1, 0, 0, 0, 1, 0]], [[1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 1], [1, 0, 1, 1, 1, 1]], [[1, 0, 0, 1, 1, 0], [1, 0, 1, 0, 1, 0], [1, 1, 0, 1, 1, 0]]]

Image description: test case explanation of the translator() function

assert() is a special function in Python that checks the equality against the function implemented output and the expected output. This will return true if it's the same output and false if otherwise.

Extra Credit

Extensions are your opportunity to customize your project, learn something else of interest to you, and improve your grade. The following are some suggested extensions, but you are free to choose your own. Be sure to describe any extensions you complete in your report.
Include pictures of the extension.

Sample Output

Please see this link to check for a sample output.