示例#1
0
	def chksave(self):
		'''BEditor -> int
			checks for saved user data, returns 1 if data exists 0 otherwise
		'''
		pickle = Pickler(self._pickle_save)
		try:
			#if this succeeds then a save file exists
			pickle.load()
			return 1
		except:
			return 0
def get_sentence_classifier(predicate, sentence_limit=None):
    try:
        ret = Pickler.load(models_cache_path % ("svmmodel-%s.pkl" % predicate))
        ret.classifier.set_params(v__analyzer=lambda x: x)
        return ret
    except IOError:
        return SentenceClassifier(predicate, sentence_limit)
示例#3
0
def get_sentence_classifier(predicate, sentence_limit=None):
    try:
        ret = Pickler.load(models_cache_path % ('svmmodel-%s.pkl' % predicate))
        ret.classifier.set_params(v__analyzer=lambda x: x)
        return ret
    except IOError:
        return SentenceClassifier(predicate, sentence_limit)
示例#4
0
	def savelog(self):
		'''(BTool)-> List of String
			returns the current list of backups on local machine, raises
			an exception if no saves exist
		'''
		p = Pickler("savelog")
		try:
			return p.load()
		except Exception, err:
			raise
示例#5
0
	def restore_library(self): #untested
		''' restore entire library to its state before changes were made 
			this process can be slow
		'''
		#get data from pickle @lib_backup
		picklesave = 'lib_backup'
		pickle = Pickler(picklesave)
		data = pickle.load()

		#update each item
		for item in data:
			self._zot.update_item(item)
def collect_entities():
    try:
        return Pickler.load(entities_path)
    except IOError:
        pass
    entities = defaultdict(list)
    for i, type in enumerate(entities_types):
        entities_of_type = select_entities_of_type(full_type_name(type))
        for entity in entities_of_type:
            entities[entity].append(i)
            if "_(" in entity:
                entities[entity.split("_(")[0]].append(i)
    Pickler.store(entities, entities_path)
    return entities
def collect_entities():
    try:
        return Pickler.load(entities_path)
    except IOError:
        pass
    entities = defaultdict(list)
    for i, type in enumerate(entities_types):
        entities_of_type = select_entities_of_type(full_type_name(type))
        for entity in entities_of_type:
            entities[entity].append(i)
            if '_(' in entity:
                entities[entity.split('_(')[0]].append(i)
    Pickler.store(entities, entities_path)
    return entities
示例#8
0
	def update_savelog(self, mode, item):
		'''(BTool, string, string)-> NoneType
			updates the savelog, adds item if mode = 'add'
			and removes item if mode = 'remove'.
			*** should only be used my backup() and restore() methods in this 
			class to ensure save corruption doesn't occur. ***
		'''
		p = Pickler("savelog")

		try: 
			#add/remove item from the list of items
			data = p.load()
			if mode == "add":
				data.append(item)
			else:
				data.remove(item)
			p.save(data)
		except:
			#in this case there is no savelog, so make one containing item
			data = []
			data.append(item)
			p.save(data) 
示例#9
0
 def get_candidates(predicate):
     try:
         return Pickler.load(candidates_cache_path % predicate)
     except IOError:
         pass
     types = CandidatesSelector.get_most_specific_types(
         CandidatesSelector.get_predominant_types(predicate))
     if types:
         candidates = select_entities_of_type_not_in_relation(
             types[0], predicate)
         if predicate == 'gmina':
             candidates = filter(lambda e: 'Gmina' not in e, candidates)
         if predicate == 'powiat':
             candidates = filter(lambda e: 'Powiat' not in e, candidates)
         if predicate == 'hrabstwo':
             candidates = filter(
                 lambda e: 'hrabstwo_miejskie' not in e and 'Hrabstwo'
                 not in e, candidates)
         Pickler.store(candidates, candidates_cache_path % predicate)
         return candidates
     else:
         return []
 def get_candidates(predicate):
     try:
         return Pickler.load(candidates_cache_path % predicate)
     except IOError:
         pass
     types = CandidatesSelector.get_most_specific_types(
         CandidatesSelector.get_predominant_types(predicate)
     )
     if types: 
         candidates = select_entities_of_type_not_in_relation(
             types[0], 
             predicate
         )
         if predicate == 'gmina':
             candidates = filter(lambda e: 'Gmina' not in e, candidates)
         if predicate == 'powiat':
             candidates = filter(lambda e: 'Powiat' not in e, candidates)
         if predicate == 'hrabstwo':
             candidates = filter(lambda e: 'hrabstwo_miejskie' not in e and 'Hrabstwo' not in e, candidates)
         Pickler.store(candidates, candidates_cache_path % predicate)
         return candidates
     else:
         return []
示例#11
0
	def restore(self, version):
		'''(BTool, str)-> NoneType
		'''
		#backup current library
		#self.backup()

		#delete all library data
		zot = zotero.Zotero(self._userData['user_id'],
							self._userData['user_type'],
							self._userData['api_key'])

		items = zot.items()

		for item in items:
			zot.delete_item(item)

		#add old library data
		p = Pickler(version)
		items = p.load()
		
		for item in items:
			item["data"]["version"] = 0
			item["key"] = ''
			r = zot.create_items([item])
def get_article(name):
    try:
        return Pickler.load(articles_cache_path % name)[: article_sentence_limit]
    except IOError:
        raise ArticleNotFoundError(name)
示例#13
0
def get_article(name):
    try:
        return Pickler.load(articles_cache_path %
                            name)[:article_sentence_limit]
    except IOError:
        raise ArticleNotFoundError(name)