From eb994d96bb679acc92f73d6b70c6ad90190223de Mon Sep 17 00:00:00 2001 From: Nim Nahum Date: Wed, 28 Oct 2015 09:47:36 -0700 Subject: [PATCH 1/2] removing words and sentences from output of Analysis --- model.go | 2 -- sentiment.go | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/model.go b/model.go index 9b37ea7f1..a81f7a1d6 100644 --- a/model.go +++ b/model.go @@ -85,7 +85,5 @@ type SentenceScore struct { // code type Analysis struct { Language Language `json:"lang"` - Words []Score `json:"words"` - Sentences []SentenceScore `json:"sentences,omitempty"` Score uint8 `json:"score"` } diff --git a/sentiment.go b/sentiment.go index aace52090..39cba4a25 100644 --- a/sentiment.go +++ b/sentiment.go @@ -18,18 +18,19 @@ func (m Models) SentimentAnalysis(sentence string, lang Language) *Analysis { analysis := &Analysis{ Language: lang, - Words: []Score{}, +// Words: []Score{}, Score: uint8(0), } sentences := strings.FieldsFunc(sentence, SplitSentences) + mySentences := []SentenceScore{} + myWords := []Score{} if len(sentences) > 1 { - analysis.Sentences = []SentenceScore{} for _, s := range sentences { class, P := m[lang].Probability(s) - analysis.Sentences = append(analysis.Sentences, SentenceScore{ + mySentences = append(mySentences, SentenceScore{ Sentence: s, Score: ScaleScores(class, P, lang), Probability: P, @@ -41,7 +42,7 @@ func (m Models) SentimentAnalysis(sentence string, lang Language) *Analysis { for _, word := range w { class, P := m[lang].Probability(word) - analysis.Words = append(analysis.Words, Score{ + myWords = append(myWords, Score{ Word: word, Score: ScaleScores(class, P, lang), Probability: P, @@ -52,18 +53,18 @@ func (m Models) SentimentAnalysis(sentence string, lang Language) *Analysis { if class, P := m[lang].Probability(sentence); !math.IsNaN(P) { fmt.Printf("Sentence: %v\tClass > Probability: %v > %v\n", sentence, int(class), P) analysis.Score = ScaleScores(class, P, lang) - } else if len(analysis.Sentences) != 0 { + } else if len(mySentences) != 0 { sum := float64(0) - for i := range analysis.Sentences { - sum += float64(analysis.Sentences[i].Score) + for i := range mySentences { + sum += float64(mySentences[i].Score) } - analysis.Score = uint8(math.Floor(sum / float64(len(analysis.Sentences)))) + analysis.Score = uint8(math.Floor(sum / float64(len(mySentences)))) } else { sum := float64(0) - for i := range analysis.Words { - sum += float64(analysis.Words[i].Score) + for i := range myWords { + sum += float64(myWords[i].Score) } - analysis.Score = uint8(math.Floor(sum / float64(len(analysis.Sentences)))) + analysis.Score = uint8(math.Floor(sum / float64(len(mySentences)))) } return analysis From b07ece1bf2ac9d0874affa84b7227aa09a623e74 Mon Sep 17 00:00:00 2001 From: Nim Nahum Date: Wed, 28 Oct 2015 09:50:15 -0700 Subject: [PATCH 2/2] removing commented out line --- sentiment.go | 1 - 1 file changed, 1 deletion(-) diff --git a/sentiment.go b/sentiment.go index 39cba4a25..93d82e12b 100644 --- a/sentiment.go +++ b/sentiment.go @@ -18,7 +18,6 @@ func (m Models) SentimentAnalysis(sentence string, lang Language) *Analysis { analysis := &Analysis{ Language: lang, -// Words: []Score{}, Score: uint8(0), }