【发布时间】:2015-10-12 05:38:12
【问题描述】:
您好,我是编程新手,几周前才开始。如果我能得到一些帮助,将不胜感激。提前致谢!
我的 python 脚本 (stream_tweets.py) 每分钟从 twitter 传输 200 - 300 条推文。该脚本位于'/home/computer/Twitter/examples/stream_tweets.py'
我有一个 NLP(自然语言处理)bash 脚本,可以分析句子并在 bash 上打印出来。 NLP 脚本 (corenlp.sh) 位于 '/home/computer/Standford/corenlp.sh'
如果我创建一个新的 bash 脚本,如何将推文通过管道传输到 NLP?这个脚本会是什么样子?
我的 python 推文脚本 (stream_tweets.py) 需要输出 utf-8 格式的文本,我该如何更改脚本。
NLP 需要一段时间才能加载,如果推文涌入尚未加载的 NLP,会影响我的脚本吗?如果可以,我该怎么做?如何做?
-
看看 stream_twitter.py 脚本
from TwitterAPI import TwitterAPI TRACK_TERM = ‘keyword1,keyword2,keyword3' CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ACCESS_TOKEN_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ACCESS_TOKEN_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' api = TwitterAPI(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET) r = api.request('statuses/filter', {'track': TRACK_TERM}) for item in r: print(item['text'] if 'text' in item else item) -
看看 NLP 脚本
OS=`uname` # Macs (BSD) don't support readlink -e if [ "$OS" == "Darwin" ]; then scriptdir=`dirname $0` else scriptpath=$(readlink -e "$0") || scriptpath=$0 scriptdir=$(dirname "$scriptpath") fi echo java -mx3g -cp \"$scriptdir/*\" edu.stanford.nlp.pipeline.StanfordCoreNLP $* java -mx3g -cp "$scriptdir/*" edu.stanford.nlp.pipeline.StanfordCoreNLP $*
【问题讨论】:
标签: python twitter stream pipe nlp