반응형
/*******************************************************************************************************************
-- Title : [Py3.5] Word Listing, Spelling, Counting, Translating and Detecting w/ TextBlob
-- Reference : textblob.readthedocs.io/en/dev/quickstart.html
-- Key word : textblob wordlist spellcheck correct word_counts words count noun_phrases.count
translate detect_language nlp 자연어처리 번역 blob 단수 복수 철자 어수
*******************************************************************************************************************/
■ 단복수/철자/단어수 등의 Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | # -*- coding: utf-8 -*- from textblob import TextBlob from textblob import Word # TextBlob API Reference : textblob.readthedocs.io/en/dev/api_reference.html#textblob.blob.TextBlob.noun_phrases # ------------------------------ # -- WordLists # ------------------------------ animals = TextBlob("cat dog octopus") print ("Rawdata: ",animals.words) print ("Pluralize:", animals.words.pluralize()) print ("... wordlist.pluralize", "." * 100, "\n") # ------------------------------ # -- Spelling # ------------------------------ # -- spelling correct aa = TextBlob("I havv goood speling!") print (aa, " -> ", aa.correct()) bb = TextBlob("Oh my gud!") print (bb, " -> ", bb.correct()) print (",,, spelling correct", "," * 100, "\n") # -- spelling check cc = Word('falibility') print (cc, " -> ", cc.spellcheck()) dd = Word('resourse') print (dd, " -> ", dd.spellcheck()) print (",,, spelling check", "," * 100, "\n") # ------------------------------ # -- Counting # ------------------------------ ee = TextBlob("""We are no longer the Knights who say Ni Kang. We are now the Knights who say Ekki ekki ekki PTANG. What is the Ni Kang.""") # -- word counting print (ee) print ("->") print ("word_counts['ekki'] : ", ee.word_counts['ekki']) print ("ee.words.count('ekki') : ", ee.words.count('ekki')) print ("ee.words.count('ekki', case_sensitive=True) : ", ee.words.count('ekki', case_sensitive=True)) print ("!!! word counting", "!" * 100, "\n") # -- noun_phrase counting print (ee.noun_phrases) print ("ee.noun_phrases.count('ni kang') : ", ee.noun_phrases.count('ni kang')) print ("!!! np chunk counting", "!" * 100, "\n") # ------------------------------ # -- Translation and Detection # ------------------------------ en_blob = TextBlob(u'Simple is better than complex.') print ("원본:",en_blob, "->\n번역본:", en_blob.translate(to='es')) print ("") cn_blob = TextBlob(u"美丽优于丑陋") print ("원본:",cn_blob, "->\n번역본:", cn_blob.translate(from_lang="zh-CN", to='en')) print ("^^^ translation", "^" * 100, "\n") ff = TextBlob(u"بسيط هو أفضل من مجمع") print ("언어는:", ff.detect_language()) gg = TextBlob(u"아놔~!!") print ("언어는:", gg.detect_language()) print ("^^^ detection", "^" * 100, "\n") |
반응형