コード例 #1
0
class CNNSentimenter:
    def __init__(self):
        print "CNNSentimenter initialized"
        self.sentimenter = Sentimenter()

    def computeSentimentPart(self, text):
        result = self.sentimenter.getSentiment(text)
        return -1 + 2 * result[0][1]

    def computeSentiment(self, text):
        paragraphs = text.split('\n')
        sentiments = []
        for i in range(0, len(paragraphs)):
            par = paragraphs[i]
            pid = "p" + str(i)
            psent = self.computeSentimentPart(par)
            sentences = re.split('([.|!|?]) ', par)
            pardict = {}
            sentenceslist = []
            j = 0
            while j < len(sentences):
                sentence = sentences[j]

                if (len(sentences) > j + 1):
                    sentence = sentence + sentences[j + 1]
                sid = pid + "-" + str(j)
                ssent = self.computeSentimentPart(sentence)
                sdict = {'id': sid, 'score': ssent, 'text': sentence}
                sentenceslist.append(sdict)

                j = j + 2
            pardict['id'] = pid
            pardict['score'] = psent
            pardict['sentences'] = sentenceslist
            sentiments.append(pardict)

        return {'paragraphs': sentiments}
コード例 #2
0
class CNNSentimenter:
	def __init__(self):
		print "CNNSentimenter initialized"
		self.sentimenter = Sentimenter()

	def computeSentimentPart(self, text):
		result = self.sentimenter.getSentiment(text)
		return -1 + 2*result[0][1]		

	def computeSentiment(self, text):
		paragraphs = text.split('\n')
		sentiments = []
		for i in range(0, len(paragraphs)):
			par = paragraphs[i]
			pid = "p" + str(i)
			psent = self.computeSentimentPart(par)
			sentences = re.split('([.|!|?]) ',par)
			pardict = {}
			sentenceslist = []
			j = 0
			while j < len(sentences):
				sentence = sentences[j]
				
				if(len(sentences) > j+1):
					sentence = sentence + sentences[j+1]
				sid = pid +"-" + str(j)
				ssent = self.computeSentimentPart(sentence)
				sdict = {'id': sid, 'score':ssent, 'text': sentence}
				sentenceslist.append(sdict)

				j = j + 2
			pardict['id'] = pid
			pardict['score'] = psent
			pardict['sentences'] = sentenceslist
			sentiments.append(pardict)

		return {'paragraphs': sentiments}
コード例 #3
0
 def __init__(self):
     print "CNNSentimenter initialized"
     self.sentimenter = Sentimenter()
コード例 #4
0
	def __init__(self):
		print "CNNSentimenter initialized"
		self.sentimenter = Sentimenter()