Пример #1
0
def get_text_sentiment(text):
    alchemy_api_key = "ce6d4fd632e66e75542c39f00d5408962ac58697"
    alchemy_language = AlchemyLanguage(api_key=alchemy_api_key)
    result = alchemy_language.sentiment(text=text)
    if result['docSentiment']['type'] == 'neutral':
        return 'netural', 0
    return result['docSentiment']['type'], result['docSentiment']['score']
Пример #2
0
def main():
    alchemy_api_key = os.environ.get("ALCHEMY_API_KEY")
    alchemy_language = AlchemyLanguage(api_key=alchemy_api_key)

    text = "I hate galvanize"

    sentiment, score = get_text_sentiment(alchemy_language, text)
    print(sentiment, score)
Пример #3
0
def get_text_sentiment(text):
    alchemy_api_key = os.environ.get("ALCHEMY_API_KEY")

    alchemy_language = AlchemyLanguage(api_key=alchemy_api_key)
    result = alchemy_language.sentiment(text=text)
    if result['docSentiment']['type'] == 'neutral':
        return 'netural', 0
    return result['docSentiment']['type'], result['docSentiment']['score']
Пример #4
0
def get_text_sentiment(text):
    #return a dictionary containing text sentiment and values
    alchemy_api_key = config.ALCHEMY_API_KEY
    alchemy_language = AlchemyLanguage(api_key=alchemy_api_key)
    result = alchemy_language.sentiment(text=text)

    #Uncomment to see FULL json output
    #print str(result)
    #print (result['docSentiment'])
    return result['docSentiment']
Пример #5
0
def get_text_emotion(text):
    #return a dictionary containing emotions and values
    alchemy_api_key = config.API_KEY
    alchemy_language = AlchemyLanguage(api_key=alchemy_api_key)
    result_emotion = alchemy_language.emotion(text=text)

    #Uncomment to see FULL json output
    #print str(result_emotion)
    print result_emotion['docEmotions']
    return result_emotion['docEmotions']
Пример #6
0
fh = logging.FileHandler('candy.log')
fh.setLevel(logging.INFO)

ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
fh.setFormatter(formatter)

logger.addHandler(ch)
logger.addHandler(fh)

load_dotenv(os.path.join(os.path.dirname(__file__), ".env"))
alchemy = AlchemyLanguage(api_key=os.environ.get("ALCHEMY_API_KEY"))
auth = WatsonAuthorization(
    username=os.environ.get("STT_USERNAME"),
    password=os.environ.get("STT_PASSWORD")
)

has_arduino = False # Stays False if "python server.py"
if len(sys.argv) > 1 and sys.argv[1] == 'arduino':
    has_arduino = True # True if user runs "python server.py arduino"

if has_arduino:
    # configure the serial connections 
    # (Parameters differ depending on the device being connected)
    ser = serial.Serial(
        port=glob.glob("/dev/tty.usbmodem*")[0],
        baudrate=9600,
Пример #7
0
 def get_text_sentiment(text):
     alchemy_language = AlchemyLanguage(api_key=self.alchemytoken)
     result = alchemy_language.sentiment(text=text)
     if result[‘docSentiment’][‘type’] == ‘neutral’:
         return ‘netural’, 0