龙空技术网

python编程实现KWIC算法(轮排索引)

喜欢编程的猪 69

前言:

此时兄弟们对“python 快排算法”大体比较关怀,我们都想要分析一些“python 快排算法”的相关资讯。那么小编也在网络上网罗了一些关于“python 快排算法””的相关资讯,希望兄弟们能喜欢,你们一起来了解一下吧!

'''python编程实现KWIC算法(轮排索引)1、KWIC(keyword-in-context)索引,即置换索引(permuted index)、轮排索引(rotated index,permuted index)用轮排法编制成的索引。其用途是对主题词实施词形控制,充分显示主题词中每一个有检索意义的成分,使主题词有更多被检出的机会,以部分满足族性检索的需要。检索系统接受有序的行集合:每一行是单词的有序集合;每一个单词又是字母的有序集合。通过重复地删除行中第一个单词,并把它插入行尾,每一行可以被“循环地移动”。KWIC检索系统以字母表的顺序输出一个所有行循环移动的列表。2、参考资料置换索引(KWIC index)的简单例子、实现效果1)输入The quick brown foxjumped over the fence2)输出          The quick | brown fox    jumped over the | fence    The quick brown | fox                    | jumped over the fence             jumped | over the fence                The | quick brown fox        jumped over | the fence                    | The quick brown fox'''#词组列表lines=[]lines.append("The quick brown fox".split())lines.append("jumped over the fence".split())#生成轮排索引rotated_idx=[]for i,line in enumerate(lines):    for j in range(len(line)):        rotated_idx.append([i,j])print(lines)print(rotated_idx)#排序轮排索引for i in range(len(rotated_idx)):    min_idx = i    min_word = lines[rotated_idx[i][0]][rotated_idx[i][1]]    for j in range(i+1,len(rotated_idx)):        s=lines[rotated_idx[j][0]][rotated_idx[j][1]]        if s.lower()<min_word.lower():            min_idx = j            min_word = s    if min_idx!=i:        temp = rotated_idx[i]        rotated_idx[i] = rotated_idx[min_idx]        rotated_idx[min_idx] = temp#排序效果for it in rotated_idx:    print(lines[it[0]][it[1]])#输出轮排索引for it in rotated_idx:    line_idx = it[0]    word_idx = it[1]    s1=''    for i in range(word_idx):        s1 += lines[line_idx][i]+' '    n = len(s1)    s1 =  ' '*(20-n) + s1#实现居右对齐    s1 = s1[-100:] + '|'    s2 = ''    for i in range(word_idx,len(lines[line_idx])):        s2 += lines[line_idx][i] + ' '    print(s1,s2)

标签: #python 快排算法