mirror of
https://github.com/fumiama/jieba.git
synced 2026-06-24 05:06:23 +08:00
fixed the test failure in textrank
This commit is contained in:
@@ -123,23 +123,20 @@ func (t *TextRanker) TextRankWithPOS(sentence string, topK int, allowPOS []strin
|
|||||||
g := newUndirectWeightedGraph()
|
g := newUndirectWeightedGraph()
|
||||||
cm := make(map[[2]string]float64)
|
cm := make(map[[2]string]float64)
|
||||||
span := 5
|
span := 5
|
||||||
wordTags := make([]posseg.WordTag, 0)
|
pairs := make([]posseg.Pair, 0)
|
||||||
for wordTag := range t.Cut(sentence, true) {
|
for pair := range t.Cut(sentence, true) {
|
||||||
wordTags = append(wordTags, wordTag)
|
pairs = append(pairs, pair)
|
||||||
}
|
}
|
||||||
for i, _ := range wordTags {
|
for i, _ := range pairs {
|
||||||
if _, ok := posFilt[wordTags[i].Tag]; ok {
|
if _, ok := posFilt[pairs[i].Flag]; ok {
|
||||||
for j := i + 1; j < i+span; j++ {
|
for j := i + 1; j < i+span && j <= len(pairs); j++ {
|
||||||
if j > len(wordTags) {
|
if _, ok := posFilt[pairs[j].Flag]; !ok {
|
||||||
break
|
|
||||||
}
|
|
||||||
if _, ok := posFilt[wordTags[j].Tag]; !ok {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, ok := cm[[2]string{wordTags[i].Word, wordTags[j].Word}]; !ok {
|
if _, ok := cm[[2]string{pairs[i].Word, pairs[j].Word}]; !ok {
|
||||||
cm[[2]string{wordTags[i].Word, wordTags[j].Word}] = 1.0
|
cm[[2]string{pairs[i].Word, pairs[j].Word}] = 1.0
|
||||||
} else {
|
} else {
|
||||||
cm[[2]string{wordTags[i].Word, wordTags[j].Word}] += 1.0
|
cm[[2]string{pairs[i].Word, pairs[j].Word}] += 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user