Guest User

Untitled

a guest
Mar 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. TextBlob
  2. TextBlob stands on the giant shoulders of NLTK and pattern, and plays nicely with both.
  3.  
  4. Noun phrase extraction
  5. Part-of-speech tagging
  6. Sentiment analysis
  7. Classification (Naive Bayes, Decision Tree)
  8. Language translation and detection powered by Google Translate
  9. Tokenization (splitting text into words and sentences)
  10. Word and phrase frequencies
  11. Parsing
  12. n-grams
  13. Word inflection (pluralization and singularization) and lemmatization
  14. Spelling correction
  15. Add new models or languages through extensions
  16. WordNet integration
  17.  
  18.  
  19. $ pip install -U textblob
  20. $ python -m textblob.download_corpora
  21.  
  22.  
  23.  
  24. from textblob import TextBlob
  25.  
  26. text = '''
  27. The titular threat of The Blob has always struck me as the ultimate movie
  28. monster: an insatiably hungry, amoeba-like mass able to penetrate
  29. virtually any safeguard, capable of--as a doomed doctor chillingly
  30. describes it--"assimilating flesh on contact.
  31. Snide comparisons to gelatin be damned, it's a concept with the most
  32. devastating of potential consequences, not unlike the grey goo scenario
  33. proposed by technological theorists fearful of
  34. artificial intelligence run rampant.
  35. '''
  36.  
  37. blob = TextBlob(text)
  38. blob.tags # [('The', 'DT'), ('titular', 'JJ'),
  39. # ('threat', 'NN'), ('of', 'IN'), ...]
  40.  
  41. blob.noun_phrases # WordList(['titular threat', 'blob',
  42. # 'ultimate movie monster',
  43. # 'amoeba-like mass', ...])
  44.  
  45. for sentence in blob.sentences:
  46. print(sentence.sentiment.polarity)
  47. # 0.060
  48. # -0.341
  49.  
  50. blob.translate(to="es") # 'La amenaza titular de The Blob...'
  51.  
  52.  
  53. The pattern.en module contains a fast part-of-speech tagger for English
  54. (identifies nouns, adjectives, verbs, etc. in a sentence), sentiment analysis,
  55. tools for English verb conjugation and noun singularization & pluralization, and a WordNet interface.
Add Comment
Please, Sign In to add comment