Przeglądaj źródła

修改 computeTokenProximity 下标细节

实现 https://github.com/3xian/wukong/commit/55c63d9fed56bd817d28f84e58e654dedd4130a6#commitcomment-5094494 的修改建议
Wei Dai 12 lat temu
rodzic
commit
7efd06c170
1 zmienionych plików z 5 dodań i 5 usunięć
  1. 5 5
      core/indexer.go

+ 5 - 5
core/indexer.go

@@ -331,8 +331,8 @@ func computeTokenProximity(table []*KeywordIndices, indexPointers []int, tokens
 	// 动态规划
 	currentLocations = table[0].locations[indexPointers[0]]
 	currentMinValues = make([]int, len(currentLocations))
-	for i := 0; i+1 < len(tokens); i++ {
-		nextLocations = table[i+1].locations[indexPointers[i+1]]
+	for i := 1; i < len(tokens); i++ {
+		nextLocations = table[i].locations[indexPointers[i]]
 		nextMinValues = make([]int, len(nextLocations))
 		for j, _ := range nextMinValues {
 			nextMinValues[j] = -1
@@ -343,7 +343,7 @@ func computeTokenProximity(table []*KeywordIndices, indexPointers []int, tokens
 			if currentMinValues[iCurrent] == -1 {
 				continue
 			}
-			for iNext+1 < len(nextLocations) && nextLocations[iNext] < currentLocation {
+			for iNext+1 < len(nextLocations) && nextLocations[iNext+1] < currentLocation {
 				iNext++
 			}
 
@@ -351,10 +351,10 @@ func computeTokenProximity(table []*KeywordIndices, indexPointers []int, tokens
 				if to >= len(nextLocations) {
 					return
 				}
-				value := currentMinValues[from] + utils.AbsInt(nextLocations[to]-currentLocations[from]-len(tokens[i]))
+				value := currentMinValues[from] + utils.AbsInt(nextLocations[to]-currentLocations[from]-len(tokens[i-1]))
 				if nextMinValues[to] == -1 || value < nextMinValues[to] {
 					nextMinValues[to] = value
-					path[i+1][to] = from
+					path[i][to] = from
 				}
 			}