2017-12-30 15 views
2

태그 : 제가 예를 trump의 코드를 사용하면트윗 온도 : 항상 같은 감정 평가 점수를 반환 상관없이 내가 cryptocurrencies에 대한 감정 점수를 생성하려면이 라이브러리를 사용하는 것을 시도하고있다

https://github.com/uclatommy/tweetfeels/blob/master/README.md

, 그것은 반환은 감정 점수는 -0.00082536637608123106입니다.

나는 다음에 태그를 변경 :

btc_feels = TweetFeels(login, tracking=['bitcoin']) 
btc_feels.start(20) 
btc_feels.sentiment.value 

하고 여전히 나에게 같은 값을 제공합니다.

라이브러리를 설치했을 때 이상한 점을 발견했습니다. 지침에서

:

만약 어떤 이유로 핍은 베이더 사전 설치하지 않은 경우 :

을 python3 -m nltk.downloader vader_lexicon

내가 달릴 때 이걸 가지고있어 :

/anaconda/lib/python3.6/runpy.py:125 : RuntimeWarning : 패키지 'nltk', 을 가져온 후 'nltk.downloader'를 실행하기 전에 sys.modules에 'nltk.downloader'가 있습니다. 그것이 작동하지 나타나는 이유는 (RuntimeWarning (MSG)가)

이 될 수 있을까요 경고를해서 예기치 않은 동작이 발생할 수 있습니다?

답변

1

기본적으로 tweetfeels는 현재 디렉토리에 데이터베이스를 만듭니다. 다음에 프로그램을 시작하면 동일한 데이터베이스를 계속 사용하고 중단 한 부분부터 다시 시작합니다. tweetfeels가 키워드를 변경하는 데 어떤 영향을 미치는지는 모르겠지만 tweetfeels의 이러한 동작은 문제가 될 수 있습니다. 해결책은 다른 키워드에 대해 다른 데이터베이스를 사용한 다음 데이터베이스의 위치를 ​​TweetFeels 생성자에 전달하는 것입니다.

Tweetfeels에 대해 많이 알지 못합니다. 흥미 롭기 때문에 프로젝트를 다운로드했으며, 필자가 제공하는 키워드에 대한 정서 분석을 수행하는 작업 스크립트가 있습니다. TweetFeels을 작동시키는 데 여전히 문제가 있다면 여기에 스크립트 사본을 추가 할 수 있습니다.


편집 : 나는 나는 현재 스크립트 다음과 같은 문제가 발생하고

를 사용하고 여기에 스크립트.

1) 내가 갖고있는 것과 다른 오류가 발생했지만, tweetfeels 라이브러리를 pip에서 Github 저장소의 최신 코드로 바꾸어서 문제를 해결할 수있었습니다.

2) 감정 수치가보고되지 않으면 ctrl + c 키보드 인터럽트를 강제로 보내지 않고 tweetfeels가 완전히 중지되지 않는 경우가 있습니다.

import os, sys, time 
from threading import Thread 
from pathlib import Path 

from tweetfeels import TweetFeels 

consumer_key = 'em...' 
consumer_secret = 'aF...' 
access_token = '25...' 
access_token_secret = 'd3...' 
login = [consumer_key, consumer_secret, access_token, access_token_secret] 

try: 
    kw = sys.argv[1] 
except IndexError: 
    kw = "iota" 

try: 
    secs = int(sys.argv[2]) 
except IndexError: 
    secs = 15 

for arg in sys.argv: 
    if (arg == "-h" or arg == "--help"): 
     print("Gets sentiment from twitter.\n" 
       "Pass in a search term, and how frequently you would like the sentiment recalculated (defaults to 15 seconds).\n" 
       "The keyword can be a comma seperated list of keywords to look at.") 
     sys.exit(0) 

db = Path(f"~/tweetfeels/{kw}.sqlite").expanduser() 
if db.exists(): 
    print("existing db detected. Continueing from where the last sentiment stream left off") 
else: 
    #ensure the parent folder exists, the db will be created inside of this folder 
    Path(f"~/tweetfeels").expanduser().mkdir(exist_ok=True) 

feels = TweetFeels(login, tracking=kw.split(","), db=str(db)) 

go_on = True 
def print_feels(feels, seconds): 
    while go_on: 
     if feels.sentiment: 
      print(f"{feels.sentiment.volume} tweets analyzed from {feels.sentiment.start} to {feels.sentiment.end}") 
      print(f'[{time.ctime()}] Sentiment Score: {feels.sentiment.value}') 
      print(flush=True) 
     else: 
      print(f"The datastream has not reported a sentiment value.") 
      print(f"It takes a little bit for the first tweets to be analyzed (max of {feels._stream.retry_time_cap + seconds} seconds).") 
      print("If this problem persists, there may not be anyone tweeting about the keyword(s) you used") 
      print(flush=True) 
     time.sleep(seconds) 


t = Thread(target=print_feels, kwargs={"feels":feels,"seconds":secs}, daemon=True) 
print(f'Twitter posts containing the keyword(s) "{kw}" will be streamed, and a new sentiment value will be recalculated every {secs} seconds') 
feels.start() 
time.sleep(5) 
t.start() 

try: 
    input("Push enter at any time to stop the feed...\n\n") 
except (Exception, KeyboardInterrupt) as e: 
    feels.stop() 
    raise e 

feels.stop() 
go_on = False 
print(f"Stopping feed. It may take up to {feels._stream.retry_time_cap} for the feed to shut down.\n") 
#we're waiting on the feels thread to stop 
+0

안녕하세요! 스크립트를 복사 해 주시겠습니까? 많은 감사합니다 !! –

+0

나는 지금 내 스크립트를 대답에 추가했다. –

2

아니요, 인쇄물과 동일한 느낌의 값은 데이터 세트를 다운로드 할 때 경고 메시지와 관련이 없습니다.

같은 감정 점수의 문제

these lines에서 오는 :

for s in sentiments: 
    pass 
return s 

내가이 언 바운드 변수 s은 감정 점수의 이전 값을 기억하고 있다고 생각한다.

그러나이 문제는 start() 함수를 실행 한 직후에 점수를 인쇄하여 멀티 스레드 프로그램을 시작하여 트위터에서 데이터를 지속적으로 업데이트한다는 점에서 문제가되지 않습니다. 사용자 바로 다음에 정서 점수가 올 것으로 예상해서는 안됩니다. 업데이트를 시작했습니다.

README에있는 예제는 start() 함수 실행 후 Python 터미널에서 Timer completed. Disconnecting now... 메시지가 나타날 때까지 표시됩니다.

+0

완료 메시지를 기다렸습니다. –