Notice
Recent Posts
Recent Comments
Today
Total
05-15 00:00
Archives
관리 메뉴

Jeongchul Kim

10 개방형 플랫폼 - Node-RED 트위터 감정기반 분석 프로젝트 본문

사물인터넷

10 개방형 플랫폼 - Node-RED 트위터 감정기반 분석 프로젝트

김 정출 2016. 2. 1. 22:34

10 개방형 플랫폼 - Node-RED 트위터 감정기반 분석 프로젝트 종합 실습

6. 종합적인 실습

트위터에서 구글 관련 내용을 파싱하여 감정 노드를 이용해 분석하여 메세지 출력하는 예제

트위터 파싱, 관련 내용 파싱, 감정 분석, 노드 분석, 메세지 출력



트위터(Twitter) 노드를 드래그하여 추가

트위터(Twitter) 노드의 내용 설정하기

로그인 아이디 입력




관심 키워드 입력 : google

디버그 노드를 추가

와이어로 노드를 연결합니다.

동작 확인 Deploy 클릭

메시지 확인

Sentiment 노드를 추가하여 메시지가 어떤 감정을 표현하고 있는지 분석합니다.

-5에서 +5까지의 정수로 표현합니다.

메시지의 감정에 대한 양만 표현하기 위해 함수 노드를 추가합니다.


msg.payload = “Sentimnet Score:” + msg.sentiment.score;

return msg.payload;

디버그 노드를 설정합니다. : Output - Complete msg object


Deploy 버튼을 클릭합니다.


메세지 확인합니다. -1은 부정적이며, 0은 중립적이고, 3,4는 호감을 표시합니다.



SNS 트위터를 이용하여 감정분석(감정 분석)을 실시하여 Raspberry PI LED로 나타내기



Sentiment.html 소스 보기

<script type=”text/x-red” data-template-name=”sentiment”>

<div class = form-row”>

<label for=”node-input-name”><i class=”fa fa-tag”></i>Name</label>

<input type=”text” id=”node-input-name” placeholder=”Name”>

</div>

</script>


<script type=”text/x-red” data-help-name=”sentiment”>

<p>Analyses the <b>msg.payload</b>and adds a <b>msg.sentiment</b>

object that contains the resulting AFINN-111 sentiment score as <b>

msg.sentiment.score</b>.</p>

<p> A score greater than zero is positive and less than zero is negative. </p>

<p> The score typically ranges from -5 to +5, but can go higher and lower. </p>

<p> An object of word score overrides can be supplied as <b>msg.overrides</b>.</p>

<p> See <a href=”https://github.com/thisandagain/sentiment/blob/master/README.md” target=”_new”>the Sentiment docs here </a>.</p>

<script>

<script type=”text/javascript”>

RED.nodes.registerType(‘sentiment’,{

category: ‘analysis-function’,

color:”#E6E0F8”,

defaults: { name: {value:””}, },

inputs:1,

outputs:1,

icon:”arrow-in.png”,

label: function() { return this.name||”sentiment”; },

labelStyle: function() { return this.name ?”node_label_italic”:””; } });

<script>





Sentiment.js

module.exports = function(RED) {

“use strict”;

var sentiment = require(‘sentiment’);

function SentimentNode(n) {

RED.nodes.createNode(this,n);

var node = this;


this.on(“input”, function(msg) {

if(msg.hasOwnProperty(“payload”)) {

sentiment(msg.payload, msg.overrides || null, function(err,result) {

msg.sentiment = result;

node.send(msg);

});

}

else { node.send(msg); } //if no payload -just pass it on.

});

}

RED.nodes.registerType(“sentiment”, SentimentNode);

}






Comments