Skip to content

Instantly share code, notes, and snippets.

@netdesign
Created September 28, 2011 18:01
Show Gist options
  • Select an option

  • Save netdesign/1248689 to your computer and use it in GitHub Desktop.

Select an option

Save netdesign/1248689 to your computer and use it in GitHub Desktop.
text stats
text = TokenizedText
def textStats(text):
length = 0
punctuation = 0
smallWordsCount = 0
for word in text:
if(word == "," or word == "." or word == ";" or word == ":"):
punctuation += 1
else:
wordLength = len(word)
length += wordLength
if(wordLength <= 3):
smallWordsCount += 1
return {'avgWordLength':length/(len(text)-punctuation),'numWords':len(text), 'punctNum':punctuation, 'smallWordCound':smallWordsCount, 'phraseAvgSize':(len(text)/punctuation)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment