本文整理汇总了Python中corpus.Corpus.getAttributeVal方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.getAttributeVal方法的具体用法?Python Corpus.getAttributeVal怎么用?Python Corpus.getAttributeVal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.getAttributeVal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Example
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import getAttributeVal [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self)
self.parent = parent
self.processor = TextProcessor()
self.initUI()
def readCorpus(self, path):
self.data = Corpus(path)
self.processor.calculateConditionalFrequency(self.data, self.selCategory.get())
#self.processor.calculateTotalTermFrequency(self.data)
self.categoryOption['menu'].delete(0, 'end')
for attr in self.data.attributes:
self.categoryOption['menu'].add_command(label=attr, command=lambda v=attr: self.changeCategory(v) )
self.curdoc=0
self.txt1.delete('1.0', END)
self.txt1.insert('1.0', self.data.docs[self.curdoc].text)
def refreshTextInfo(self):
if self.selCategory.get() != 'Categories':
idcat = self.data.attributes.index(self.selCategory.get())
self.entry1.delete(0, END)
self.entry1.insert(0, self.data.getAttributeVal(self.curdoc, self.selCategory.get() ))
self.txt1.delete('1.0', END)
self.txt1.insert('1.0', self.data.docs[self.curdoc].text)
self.applyProcessing()
def changeCategory(self, value):
self.selCategory.set(value)
self.entry1.delete(0, END)
self.entry1.insert(0, self.data.getAttributeVal(self.curdoc, self.selCategory.get()))
self.processor.calculateConditionalFrequency(self.data, self.selCategory.get())
def prevDocument(self):
if self.curdoc>0:
self.curdoc-=1
self.refreshTextInfo()
def nextDocument(self):
if self.curdoc<self.data.ndocs-1:
self.curdoc+=1
self.refreshTextInfo()
def popup(self, event):
print "hello "+str(event.widget)
self.popupmenu.tk_popup(event.x_root, event.y_root, 0)
print event.widget.index("@%s,%s" % (event.x, event.y))
def applyProcessing(self):
if self.selCategory.get() != 'Categories':
indxCat = self.data.attributes.index( self.selCategory.get() )
textResult = self.processor.process(self.data.docs[self.curdoc], indxCat)
else:
textResult = ""
self.txt2.delete('1.0', END)
self.txt2.insert('1.0', textResult)
def loadCorpus(self):
path = tkFileDialog.askdirectory()
self.readCorpus(path)
self.refreshTextInfo()
def hello(self):
print "Hello"
def initUI(self):
self.parent.title("Simple")
self.pack(fill=BOTH, expand=True)
self.centerWindow()
sw = self.parent.winfo_screenwidth()
sh = self.parent.winfo_screenheight()
frame1 = Frame(self, relief=RAISED, borderwidth=1)
frame1.pack(fill=X)
button1 = Button(frame1, text=u"<", command=self.prevDocument)
button1.pack(side=LEFT, padx=5, pady=5)
button2 = Button(frame1, text=u">", command=self.nextDocument)
button2.pack(side=LEFT, padx=5, pady=5)
self.selCategory = StringVar(self)
self.categoryOption = OptionMenu(frame1, self.selCategory, *["Categories"], command=self.changeCategory)
self.categoryOption.pack(side=LEFT, padx=5, pady=5)
#.........这里部分代码省略.........