Esempio n. 1
0
	def add_query(self, query_id = '', query_class='n/a', query_terms=[]):
		my_query_terms = SuperList()
		my_query_terms.do_padding(new_len=len(self.terms), padding_data=0)
		new_terms_count = 0
		for term in query_terms:
			try:
				my_query_terms.insert_after_padding(self.terms.index(term))
			except:
				# Term not obtaied in traing phase
				new_terms_count += 1
		self.queries.append({'id': query_id, 'class': query_class, 'terms': my_query_terms, 'new_terms_count': new_terms_count})
Esempio n. 2
0
	def add_vectors(self, a=[], b=[], log_tf_a = True, log_tf_b = True):
		if not b:
			b = SuperList()
			b.do_padding(new_len=a.__len__(), padding_data=0)
		elif a.__len__() != b.__len__():
			if self.verbose: print "add_vectors:", a.__len__(), "!=", b.__len__()
			raise Exception
		sum_vector = SuperList()
		for i in range(0,a.__len__()):
			sum_vector.append(self.log_tf(a[i], do_nothing = not log_tf_a) + self.log_tf(b[i], do_nothing = not log_tf_b))
		return sum_vector
Esempio n. 3
0
	def add_query(self, query_id = '', query_class='n/a', query_terms=[]):
		my_query_terms = SuperList()
		my_query_terms.do_padding(new_len=len(self.terms), padding_data=0)
		for term in query_terms:
			try:
				my_query_terms.insert_after_padding(self.terms.index(term))
			except:
				# Term not obtaied in traing phase, ignore it
				pass
		# Calling add_vectors to convert my_query_terms to log_tf values
		self.add_vectors(a=my_query_terms, log_tf_a = True)
		self.queries.append({'id': query_id, 'class': query_class, 'terms': my_query_terms})