데이터사이언스 Data Science/NLTK
NLTK (4) - 정규표현식을 사용한 문자 분해 Tokenizing sentences using regular expressions
2017. 9. 26.NLTK (4) - 정규표현식을 사용한 문자 분해 Tokenizing sentences using regular expressions RegexpTokenizer 인스턴스를 생성한 후, 매칭 토큰을 사용하기위해 정규표현식 문장에 적용시켜보자. from nltk.tokenize import RegexpTokenizer tokenizer = RegexpTokenizer("[\w']+") tokenizer.tokenize("Can't is a contraction.") Out[6]:["Can't", 'is', 'a', 'contraction']클래스를 생성하고 싶지 않다면 다음과 같은 헬퍼 함수를 이용할 수도 있다.from nltk.tokenize import regexp_tokenize regexp_toke..
NLTK (3) - 문장을 단어 단위로 분해하기 Tokenizing sentences into words
2017. 9. 25.NLTK (3) - 문장을 단어 단위로 분해하기 Tokenizing sentences into words 이제 문장을 단어 단위로 분해해보자. 텍스트 처리에 있어 단어 리스트를 생성하는 것은 기본적이고도 필수적인 작업니다. 기본적으로 아래와 같이 word_tokenize() 함수를 이용하여 처리가능하다.from nltk.tokenize import word_tokenize word_tokenize('Hello world.') Out[1]:['Hello', 'world', '.'] word_tokenize() 함수는 TreebankWordTokenizer 클래스의 인스턴스에 tokenize() 함수를 호출하는 래퍼 함수이다. 다음 코드와 같은 의미를 갖는다.from nltk.tokenize import T..
ImportError: cannot import name 'PunktWordTokenizer'
2017. 9. 25.ImportError: cannot import name PunktWordTokenizer 에서는 해결 방법으로 NLTK 버전업그레이드를 제시하고 있다. 현재 NLTK 버전은 3.2.4 이다.1234567(envalicia) root@localhost:~# pythonPython 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06)[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import nltk>>> nltk.__version__'3.2.4'Colored by Color S..
NLTK (2) - 텍스트 문장으로 분해하기 Tokenizing text into sentences
2017. 9. 25.NLTK (2) - 텍스트 문장으로 분해하기 Tokenizing text into sentences 설치가 제대로 되었는지 간단한 코드로 확인해보자. para = "Hello World. It's good to see you. Thanks for buying this book." from nltk.tokenize import sent_tokenize sent_tokenize(para)['Hello World.', "It's good to see you.", 'Thanks for buying this book.']sentence tokenization 함수를 호출해서 para를 인수로 사용한다. sent_tokenize 함수는 nltk.tokenize.punkt 모듈의 PunktSentenceTokeniz..
NLTK (1) - NLTK 및 NLTK 데이터 설치
2017. 9. 25.NLTK (1) - NLTK 및 NLTK 데이터 설치 NLTK 설치 http://www.nltk.org/install.htmlNLTK 는 파이썬 2.7, 3.4, 3.5 을 지원한다.Install NLTK : conda install nltkInstall numpy : conda install numpy12345678910111213141516171819202122232425262728293031323334353637383940(envalicia) root@localhost:~/vikander# conda install nltkFetching package metadata .........Solving package specifications: . Package plan for installation i..