From 0ca40533941d6b034df5c9ed19b38d0200f29272 Mon Sep 17 00:00:00 2001 From: Wang Bin Date: Mon, 30 Mar 2015 13:06:44 +0800 Subject: [PATCH] fixed the test failure in textrank --- analyse/textrank.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/analyse/textrank.go b/analyse/textrank.go index 2a41b3b..df04e85 100644 --- a/analyse/textrank.go +++ b/analyse/textrank.go @@ -123,23 +123,20 @@ func (t *TextRanker) TextRankWithPOS(sentence string, topK int, allowPOS []strin g := newUndirectWeightedGraph() cm := make(map[[2]string]float64) span := 5 - wordTags := make([]posseg.WordTag, 0) - for wordTag := range t.Cut(sentence, true) { - wordTags = append(wordTags, wordTag) + pairs := make([]posseg.Pair, 0) + for pair := range t.Cut(sentence, true) { + pairs = append(pairs, pair) } - for i, _ := range wordTags { - if _, ok := posFilt[wordTags[i].Tag]; ok { - for j := i + 1; j < i+span; j++ { - if j > len(wordTags) { - break - } - if _, ok := posFilt[wordTags[j].Tag]; !ok { + for i, _ := range pairs { + if _, ok := posFilt[pairs[i].Flag]; ok { + for j := i + 1; j < i+span && j <= len(pairs); j++ { + if _, ok := posFilt[pairs[j].Flag]; !ok { continue } - if _, ok := cm[[2]string{wordTags[i].Word, wordTags[j].Word}]; !ok { - cm[[2]string{wordTags[i].Word, wordTags[j].Word}] = 1.0 + if _, ok := cm[[2]string{pairs[i].Word, pairs[j].Word}]; !ok { + cm[[2]string{pairs[i].Word, pairs[j].Word}] = 1.0 } else { - cm[[2]string{wordTags[i].Word, wordTags[j].Word}] += 1.0 + cm[[2]string{pairs[i].Word, pairs[j].Word}] += 1.0 } } }