# 아래 내용은 이전 포스팅인
트위터 글(데이터) 수집하기 에서 만들어진것이 R실행 코드에서 연결되어야 실행 가능 합니다.
install.packages("plyr")
library(plyr)
hilton.text <-laply(hilton.tweets,function(t)t$getText())
head(hilton.text,3)
#긍정 단어 파일 스캔
pos.word=scan("positive-words.txt",what="character",comment.char=";")
#부정 단어 파일 스캔
neg.word=scan("negative-words.txt",what="character",comment.char=";")
#수작업으로 추가 할수도 있음 (Sample)
pos.words<-c(pos.word,"upgrade")
neg.words<-c(neg.word,"wtf","wait","waiting","epicfail","mechanical")
#
install.packages("plyr")
install.packages("stringr")
library(plyr)
library(stringr)
score.sentiment =
function(sentences, pos.words, neg.words, .progress='none')
{
require(plyr)
require(stringr)
# we got a vector of sentences. plyr will handle a list
# or a vector as an "l" for us
# we want a simple array ("a") of scores back, so we use
# "l" + "a" + "ply" = "laply":
scores = laply(sentences, function(sentence, pos.words, neg.words) {
# clean up sentences with R's regex-driven global substitute, gsub():
sentence = gsub('[[:punct:]]', '', sentence)
sentence = gsub('[[:cntrl:]]', '', sentence)
sentence = gsub('\\d+', '', sentence)
# and convert to lower case:
sentence = tolower(sentence)
# split into words. str_split is in the stringr package
word.list = str_split(sentence, '\\s+')
# sometimes a list() is one level of hierarchy too much
words = unlist(word.list)
# compare our words to the dictionaries of positive & negative terms
pos.matches = match(words, pos.words)
neg.matches = match(words, neg.words)
# match() returns the position of the matched term or NA
# we just want a TRUE/FALSE:
pos.matches = !is.na(pos.matches)
neg.matches = !is.na(neg.matches)
# and conveniently enough, TRUE/FALSE will be treated as 1/0 by sum():
score = sum(pos.matches) - sum(neg.matches)
return(score)
}, pos.words, neg.words, .progress=.progress )
scores.df = data.frame(score=scores, text=sentences)
return(scores.df)
}
#함수 실행
hilton.text<-hilton.text[!Encoding(hilton.text)=="UTF-8"]
hilton.scores=score.sentiment(hilton.text,pos.words,neg.words,.progress='text')
#실행결과 값을 히스토그램으로 표현
hist(hilton.scores$score)
hilton.scores$hotel='Hilton'
hilton.scores$code='HL'
20여년간 외식전문기업에서 디지털전화과 혁신에 관한 일을 하면서 경험하게 된 다양한 이야기를 나만의 방식으로 풀어 내고자 한다. 외식기업 뿐 아니라 소상공인 모두 지속가능한 성장을 위해서 이제는 반드시 필요 한 것이 디지털 기술의 활용이며 우리의 변화가 필요 하다.
피드 구독하기:
댓글 (Atom)
다양한 채널의 블로그 작성으로 집중이 좀 안되기도 하고 나의 회사를 운영하고 관리 하다 보니 회사의 블로그로 작성 해보는 것은 어떤가 하고 하나로 옮겨 봅니다. (주)다이닝웨이브 - 블로그 바로가기
-
웹/앱 리뉴얼 프로젝트를 진행 중에 내부에서 처리해야할 프로세스상 로직이 있었는데 오라클(데이터베이스) 단계에서 처리가 곤란하게 되어 외부서비스(웹)의 특정 URL/URI를 호출해야 되는 경우가 생겼다. 구글링으로 검색을 해도 상세히 설명 된 곳이 별...
-
# Reference URL - http://struts.apache.org/docs/tutorials.html 아래 문서는 내부 구성원을 위한 간략한 설정 및 설치를 위한 정보 공유에 목적이 있으며 IT의 구성 환경에 따라 달라 질 수 있으...
-
주로 윈도우에서 RStudio를 사용할 때는 잘 몰랐는데 이동성 때문에 Mac Ari/Book에서 사용하는 경우 한글 깨짐현상이 발생 하기도 한다. 이럴때 해야 하는 여러가지 방법이 있는데 그중에 내가 사용한 내용을 공유하고자 한다. 우선은 RS...
댓글 없음:
댓글 쓰기