|  
 
 
bsp;   word=sentence[0:maxLen] #每次取最大词长的词    29.   30.        meet=False;   #标记位, 判断是否找到该词    31.   32.        while((not meet) and (len(word)>0)):   33.            #如果词在词表中    34.            if(word in strList):   35.                wordList.append(word)   #添加到输出列表    36.                sentence=sentence[len(word):len(sentence)]#论文网 后移    37.                meet=True;   38.            #词不在词表中时    39.            else:   40.                #当词长为1时, 添加到输出表, 并后移总词位    41.                if(len(word)==1):   42.                    wordList.append(word)   43.                    sentence=sentence[len(word):len(sentence)]   44.                    meet=True;   45.                else:   46.                #当词长不为1时, 词长减1(最后一位)    47.                    word=word[0:len(word)-1]   48.    return wordList   49.   50.#主函数    51.def main():   52.    strList,maxLen=load_dict('dict.txt')   53.    print("词表中最大词长度为:",maxLen)   54.    #输入句子    55.    sentence = input('请输入中文句子:')   56.    print('输入的句子为:',sentence)   57.#   sentence='迈向充满希望的新世纪'    58.    print('输入的句子为:',sentence)   59.    length=len(sentence)   60.    print('输入的句子长度:',length)   61.    print("****************开始解析**********************")   62.    上一页  [1] [2] [3] [4] [5] [6] 下一页  
 |