优雅的tweet预处理
tweet-preprocessor的Python项目详细描述
预处理器
预处理器是用python编写的tweet数据的预处理库。
在建立基于tweet数据的机器学习系统时,需要进行预处理。这个库使清理、解析或标记tweets变得容易。
功能
当前支持清理、标记化和解析:
- 网址
- 标签
- 提及
- 保留字(RT,FAV)
- 表情符号
- 微笑
支持Python2.7和3.3+
用法
基本清洁:
>>>importpreprocessorasp>>>p.clean('Preprocessor is #awesome ? https://github.com/s/preprocessor')'Preprocessor is'
标记化:
>>>p.tokenize('Preprocessor is #awesome ? https://github.com/s/preprocessor')'Preprocessor is $HASHTAG$ $EMOJI$ $URL$'
解析:
>>>parsed_tweet=p.parse('Preprocessor is #awesome https://github.com/s/preprocessor')<preprocessor.parse.ParseResultinstanceat0x10f430758>>>>parsed_tweet.urls[(25:58)=>https://github.com/s/preprocessor]>>>parsed_tweet.urls[0].start_index25>>>parsed_tweet.urls[0].match'https://github.com/s/preprocessor'>>>parsed_tweet.urls[0].end_index58
完全可定制:
>>>p.set_options(p.OPT.URL,p.OPT.EMOJI)>>>p.clean('Preprocessor is #awesome ? https://github.com/s/preprocessor')'Preprocessor is #awesome'
默认情况下,预处理器将遍历所有选项,除非您指定了某些选项。
可用选项:
Option Name | Option Short Code |
---|---|
URL | ^{ |
Mention | ^{ |
Hashtag | ^{ |
Reserved Words | ^{ |
Emoji | ^{ |
Smiley | ^{ |
Number | ^{ |
安装
使用pip:
$ pip install tweet-preprocessor