Python代写 | cse30s21 Assignment 05: Readability Metrics

本次美国代写主要为Python生物信息学相关

Specifications
Class Readability shall derive from buit-in class str [https://docs.python.org/3/library/stdtypes.html#str], which no methods overridden, and shall offer at least the four additional
methods described below.
Any readability metrics requiring the total number of characters or letters shall consider that to be the number of characters in the text for which str.isalpha()
[https://docs.python.org/3/library/stdtypes.html#str.isalpha] or str.isdigit() [https://docs.python.org/3/library/stdtypes.html#str.isdigit()] returns True.
A word shall be any sequence of English letters, decimal digits, apostrophes, and hyphens, trimmed of leading and trailing apostrophes and hyphens. The re.split()
[https://docs.python.org/3/library/re.html#re.split] function can separate a string into its constituent words fairly easily
1)
:
>>> text = “This here’s a short body of text. It contains three \”sentences\”! OK?”
>>> re.split(“[^A-Za-z0-9′-]”, text)
[‘This’, “here’s”, ‘a’, ‘short’, ‘body’, ‘of’, ‘text’, ”, ‘It’, ‘contains’, ‘three’, ”, ‘sentences’, ”, ”, ‘OK’, ”]
The number of syllables in a word shall be dictated by the data in file /srv/datasets/syllables.txt, without regard to case. Any word not present in this dataset shall be considered a
monosyllabic word.
A sentence shall be any sequence of one or more words, with the final word indicated by the presence of a period (.), question mark (?), or exclamation point (!), and some amount of whitespace (or the
end of the text), immediately following the word, disregarding any single or double-quote characters that might precede the period/question mark/exclamation point. The regular str.split()
[https://docs.python.org/3/library/stdtypes.html#str.split] method should be useful for this purpose:
>>> text.split()
[‘This’, “here’s”, ‘a’, ‘short’, ‘body’, ‘of’, ‘text.’, ‘It’, ‘contains’, ‘three’, ‘”sentences”!’, ‘OK?’]

Readability Metric Methods
Class Readability shall be defined as follows, and offer at least the four methods described below, each of which calculates and returns the given readability metric for the given body of text
2)
:
readability.py
“””
Utility module for dealing with readability metrics of English text.
“””
from __future__ import annotations

__author__ = ‘A student in CSE 30, someone@ucsc.edu’

import math
import re
import sys

class Readability(str):
“””
Represents a string that can be assessed for readability metrics of English text.
“””

# I encourage you to add other methods!

def automated_readability_index(self) -> float:
“””
Calculates and returns the automated readability index of this text.
See: https://en.wikipedia.org/wiki/Automated_readability_index
“””
# TODO
pass

def coleman_liau_index(self) -> float:
“””
Calculates and returns the Coleman–Liau index of this text.
See: https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index
“””
# TODO
pass

def flesch_kincaid_grade(self) -> float:
“””
Calculates and returns the Flesch–Kincaid grade level of this text.
See: https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
“””
# TODO
pass

def smog_grade(self) -> float | None:
“””
Calculates and returns the SMOG grade of this text,
or None if the text contains fewer than 30 sentences.
See: https://en.wikipedia.org/wiki/SMOG
“””
# TODO
pass

if __name__ == ‘__main__’:
demo = Readability(sys.stdin.read())
# My solution has some extra (helper) methods.
# You don’t have to implement these, but I recommend doing something like it.
if hasattr(demo, ‘words’):

print(len(demo.words()), ‘words: ‘, demo.words()[:5], ‘…’)
if hasattr(demo, ‘sentences’):
print(len(demo.sentences()), ‘sentences: ‘, demo.sentences()[:5], ‘…’)
if hasattr(demo, ‘num_syllables’):
print(demo.num_syllables(), ‘syllables’)
if hasattr(demo, ‘polysyllabic_words’):
print(len(demo.polysyllabic_words()), ‘polysyllabic words: ‘,
demo.polysyllabic_words()[:5], ‘…’)
print(‘ARI’, demo.automated_readability_index())
print(‘CLI’, demo.coleman_liau_index())
print(‘FKG’, demo.flesch_kincaid_grade())
print(‘SMOG’, demo.smog_grade()