Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added testing to the detectEnglish module.

  • Loading branch information...
commit 5bbeb6600d466ff55c965e7de5db56624943c25d 1 parent 6537d55
@asweigart authored
Showing with 17 additions and 0 deletions.
  1. +17 −0 detectEnglish.py
View
17 detectEnglish.py
@@ -18,6 +18,17 @@
nonLettersPattern = re.compile('[^A-Z]')
LETTTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+
+def main():
+ print('Testing the English detection module...')
+ messages = ['The quick brown fox jumped over the yellow lazy dog.',
+ 'Hello there. lkjjfldsf dsafk alf ewfewlfjl efa',
+ 'Sumimasen. Kore wa nan desu ka?',
+ '1100010110010111001011110000']
+ for m in messages:
+ print('%s\n\t%s\n' % (m, isEnglish(m)))
+
+
def getEnglishCount(message):
# Returns the amount of words in message that appear in the dictionary.
@@ -28,6 +39,9 @@ def getEnglishCount(message):
words = message.split()
+ if not words:
+ return False # after removing non-letters, message was blank
+
# Go through each word and see how many are english words.
matches = 0
for word in words:
@@ -52,3 +66,6 @@ def isEnglish(message, wordPercentage=20):
numLetters = len(nonLettersPattern.sub('', message.upper()))
return (englishWords >= wordPercentage)
+
+if __name__ == '__main__':
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.