Tkinter中停用词选择性删除及文本高亮问题求助
问题整理
个人背景
- Tkinter初学者,通过YouTube视频和按需搜索学习
- Python面向对象知识生疏
- 母语非英语
- 处理的文本包含希腊字符,核心需求为停用词删除
程序核心目标
- 用户可加载语料库文件,读取后完成分词处理
- 用户可加载停用词文件,输出为列表格式
- 程序自动检查语料库中的词汇,将属于停用词列表的词汇加入已找到停用词(ListBox A)
- 用户可将ListBox A中的词汇移至待删除停用词(ListBox B)
- 点击「Remove stopwords」按钮后,删除语料库中所有ListBox B内的停用词(多次出现的需全部删除)
当前主要问题
- 现有
removeStopwords函数中,ListBox B的停用词删除逻辑是否正确? - 如何在Text Widget中实现待删除词汇的红色高亮:
- 将词汇从ListBox A移至B时,Text Widget中该词汇的所有实例标红
- 将词汇从B移回A时,恢复原色,实现删除预览效果
现有removeStopwords函数代码
def removeStopwords(self): if len (self.corpusText) == 0: # corpusText is just a String print("Empty") return temp=[]## Used for debugging and seeing which words get added for word in self.listBoxOfDelStopwords.get(0,self.listBoxOfDelStopwords.size()): self.updatedStopwords_Greek.append(word) print("Words to be added:"+word) #if word in self.updatedStopwords_Greek: #temp.append(word) #print(word) #print(temp) print("Total of Stopwords words:"+ str(len(self.updatedStopwords_Greek))) print("Before removal of stopwords from Text :"+str(len(self.corpusText))) for word in self.corpusText: if word in self.updatedStopwords_Greek: temp.append(word) print(temp)## Debugging reasons print(str(len(temp)))## Number of occurences not just for one stopword self.corpusText.remove(word) print("-----") print("After Removal of stopwords from Text : "+str(len(self.corpusText))) #Shows number of letters self.textBoxTest.delete("1.0",END) self.textBoxTest.insert("1.0",self.corpusText) self.labelNumOfChars.configure(text=str(len(self.corpusText))) #self.textBoxTest.insert("1.0",self.corpusTest) #print(self.corpusTest)
额外需求与疑问
- 若有更高效的实现方法,希望用初学者易懂的方式讲解
- 在StackOverflow求助时,是否必须复制全量代码?
内容的提问来源于stack exchange,提问作者RookieProgrammer
相关产品推荐
相关产品推荐

