dvlsc000 / EmergingTechnologies

0 stars 0 forks source link

CHECK PERCENTAGE OF VALID ENGLISH WORDS #12

Open dvlsc000 opened 1 month ago

dvlsc000 commented 1 month ago

Create a function that calculates the percentage of valid English words in the generated text and return it.

dvlsc000 commented 3 weeks ago

PLAN

  1. Preprocess the generated text

    • Remove punctuation and unwanted characters from generated_text by retaining only letters and spaces. Use Use list comprehension with conditional logic to replace any non-alphabetic character or punctuation with a space and split processes text into individual words.
  2. Count valid words

    • Loop through the words in the processed text and check each word against valid_words. Count the number of mathches by summing 1 for each valid word found.
  3. Calculate and return the percentage

    • Calculate the total number of words in the processed text. If there are no words, return 0 to avoid division by zero, otherwise, calculate the percetage of valid words and return the result.
dvlsc000 commented 3 weeks ago

DESIGN DECISIONS

  1. Removing non-alphabetic characters

    • Using char.isalpha() to retain only letter and replacing other characters with spaces to ensure clean word boundaries.
  2. Set-based lookups for efficiency

    • Using a set for valid_words allows for quick average-time complexity for word lookups.
  3. Conditional logic to avoid division by zero

    • Checking if total_words == 0 ensures that function handles edge cases gracefully. Returning 0 to avoid the error.
  4. Percentage calculation

    • Provides intuitive, percentage-based result, making it easy to interpret the percentage of valid English words in the generated text.