本文整理汇总了Python中index.Index.add_word方法的典型用法代码示例。如果您正苦于以下问题:Python Index.add_word方法的具体用法?Python Index.add_word怎么用?Python Index.add_word使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类index.Index
的用法示例。
在下文中一共展示了Index.add_word方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Searcher
# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import add_word [as 别名]
class Searcher():
def __init__(self,collections):
if not os.path.exists('saved_library'): # will change to be name of the .avc file ok
print("making new save data")
self.library = Library()
# for now
self.library.init_from_xml("test.avc")
else:
self.load_library('saved_library',True)
#self.savedata = open('saved_library','wb')
self.index = Index(self.library.get_clip_names())
self.tag_index = Index(self.library.get_tags())
self.col_index = Index(collections)
def load_library(self,filename,debug=False):
if debug: print("reading old save data")
with open(filename,'rb') as read:
try:
self.library = pickle.load(read)
except:
if debug: print('error reading',filename)
read.close()
os.remove(filename)
self.__init__()
def save_library(self,filename,debug=False):
if debug: print('saving data')
with open(filename,'wb') as write:
pickle.dump(self.library,write)
def quit(self):
self.save_library('saved_library',True)
def search(self,term): # let's try having 2nd value be
return self.index.by_prefix(term)
def search_tag(self,term):
return self.tag_index.by_prefix(term)
def search_col(self,term):
return self.col_index.by_prefix(term)
def add_tag_to_clip(self,tag,clip):
clip.add_tag(tag)
self.library.add_clip_to_tag(clip,tag)
self.tag_index.add_word(tag)
def remove_tag_from_clip(self,tag,clip):
clip.remove_tag(tag)
self.library.remove_clip_from_tag(clip,tag)
def remove_tag_from_library(self,tag):
self.tag_index.remove_word(tag)
self.library.remove_tag(tag)
def get_from_name(self,name):
return self.library.get_clip_from_name(name)
def has_name(self,name):
return name in self.library.clips