<s> UPPERLETTERS = '<STR_LIT>' <EOL> LETTERS_AND_SPACE = UPPERLETTERS + UPPERLETTERS . lower ( ) + '<STR_LIT>' <EOL> def loadDictionary ( ) : <EOL> dictionaryFile = open ( '<STR_LIT>' ) <EOL> englishWords = { } <EOL> for word in dictionaryFile . read ( ) . split ( '<STR_LIT:\n>' ) : <EOL> englishWords [ word ] = None <EOL> dictionaryFile . close ( ) <EOL> return englishWords <EOL> ENGLISH_WORDS = loadDictionary ( ) <EOL> def getEnglishCount ( message ) : <EOL> message = message . upper ( ) <EOL> message = removeNonLetters ( message ) <EOL> possibleWords = message . split ( ) <EOL> if possibleWords == [ ] : <EOL> return <NUM_LIT:0.0> <EOL> matches = <NUM_LIT:0> <EOL> for word in possibleWords : <EOL> if word in ENGLISH_WORDS : <EOL> matches += <NUM_LIT:1> <EOL> return float ( matches ) / len ( possibleWords ) <EOL> def removeNonLetters ( message ) : <EOL> lettersOnly = [ ] <EOL> for symbol in message : <EOL> if symbol in LETTERS_AND_SPACE : <EOL> lettersOnly . append ( symbol ) <EOL> return '<STR_LIT>' . join ( lettersOnly ) <EOL> def isEnglish ( message , wordPercentage = <NUM_LIT:20> , letterPercentage = <NUM_LIT> ) : <EOL> wordsMatch = getEnglishCount ( message ) * <NUM_LIT:100> >= wordPercentage <EOL> numLetters = len ( removeNonLetters ( message ) ) <EOL> messageLettersPercentage = float ( numLetters ) / len ( message ) * <NUM_LIT:100> <EOL> lettersMatch = messageLettersPercentage >= letterPercentage <EOL> return wordsMatch and lettersMatch </s>
