def getIDFValue(): str = '' word = request.args.get('zbor') rows = IDFModel.query(IDFModel.word == word).fetch() if rows is not None and len(rows) > 0: str += 'IDF value for word %s is %f\n' % (word, rows[0].value) else: str += 'No IDF Value for word %s\n' % word return Response(str, mimetype='text/plain')
def insertDICTIDF_task(): str = '' feedback = '' try: logging.debug('Trying to load the dictionary for idf..') fileToRead = open('dict_idf') dictIDF = Unpickler(fileToRead).load() fileToRead.close() logging.debug('Loaded the dictionary for idf!') logging.debug('Inserting words') counter = 0 for word in dictIDF: key = ndb.Key('IDFModel', word) newPair = IDFModel(parent = key, word = word, value = dictIDF[word]) newPair.put() counter += 1 if counter % 1000: logging.debug('Inserted %d words' % counter) logging.debug('Wuhu! Inserted all the words.') str += 'Inserted %d words for IDF\n' % counter except Exception as inst: feedback += 'Exception type: %s\n' % type(inst) feedback += 'Exception message: %s\n' % inst.message logging.debug(feedback) str += feedback return Response(str, mimetype='text/plain')