Exemple #1
0
		# check whether a file exists before read
		if os.path.isfile(result_item_path):
			with open(result_item_path, 'r') as f:
				# read content of query documant (doc, content)
				title = "query"
				count = 0
				rst_list = []
				for line in f.readlines():
					if "Query" in line.split():
						rst_list = []
						words = line.split()
						title = words[2]
						resultTraingSetDict[title] = ""
					else:
						words = line.split()
						if len(words) < 1: 
							resultTraingSetDict[title] = rst_list
							continue
						
						rst_list.append([words[0], words[1]])
	
	return resultTraingSetDict
	
results = get_result()
assessment = readAssessment.get_assessment()
precision_sum = 0
results = collections.OrderedDict(sorted(results.items()))
for key, value in results.items():
	print key
	precision_sum += readAssessment.precision(value , assessment[key])
print precision_sum	/ 16
                         word_probability = doc_words[
                             query_word] / doc_words_sum
                     if query_word in background_word:
                         background_probability = (
                             background_word[query_word] +
                             0.01) / (background_word_sum + 0.01)
                     else:
                         background_probability = (0.01) / (
                             background_word_sum + 0.01)
                     point += log(my_lambda * word_probability +
                                  (1 - my_lambda) * background_probability)
                 docs_point[doc_key] = point
             # sorted each doc of query by point
             docs_point_list = sorted(docs_point.items(),
                                      key=operator.itemgetter(1),
                                      reverse=True)
             AP += readAssessment.precision(docs_point_list,
                                            assessment[q_key])
         # mean average precision
         mAP = AP / len(query)
         print my_lambda
         print mAP
         lambda_test[my_lambda] = mAP
 # get key with maximum value in lambda_test dictionary
 max_lambda = max(lambda_test.iteritems(), key=operator.itemgetter(1))[0]
 max_mAP = lambda_test[my_lambda]
 # print Lambda and Max value
 print "Max:"
 print max_lambda, max_mAP
 isBreak = raw_input("exit ?\n")
 interval /= 10