예제 #1
0
파일: tq.py 프로젝트: adajw/Laura
	def post(self):
		''' Add a fingerprint to the database '''
		logging.info("A")
		fingerprint = models.fromkey(self.request.get('key'))
		logging.info("B")
		markov.build_fingerprint(fingerprint)
		logging.info("C")
		self.response.out.write("done")
예제 #2
0
파일: tq.py 프로젝트: adajw/Laura
	def post(self):
		''' Use saved comparisons to compare chain similarity,
		then use dbtools.add_counts to merge result into
		the response fingerprint '''
		response = models.fromkey(self.request.get('response'))
		sample =   models.fromkey(self.request.get('sample'))
		if sample.state != "normal":
			return
		logging.info(response.key())
		cA = response.parentprint
		cB = sample.parentprint
		roleA = Build.Role()
		roleB = Build.Role()
		simtotal = 0
		while cA and cB:
			try:
				sim = self.findSimilarity(cA,cB)
				simvalue = sim.value*.8
				if cA.author == cB.author:
					simvalue += .1
				if roleA.insert(cA.author) == roleB.insert(cB.author):
					simvalue += .1
			except IndexError:
				if cA.key() == cB.key():
					simvalue = 1.0
				else:
					# Fail if the comparison is not ready
					logging.info("Comparison not ready")
					logging.info(cA.key())
					logging.info(cB.key())
					logging.info(cA.key() == cB.key())
					self.error(500)
					return
			simtotal += simvalue
			cA = cA.parentprint
			cB = cB.parentprint
		logging.info(response.build_count)
		response.build_count += 1
		response.build_weight += simtotal
		response.put()
		logging.info(response.build_count)
		dbtools.fuse(sample, response, simtotal)
예제 #3
0
파일: tq.py 프로젝트: adajw/Laura
	def post(self):
		''' Compare two already-markovized fingerprints. Produce
		2 models.Similarity objects, sacrificing storage space
		for CPU speed. '''
		if self.request.get('A') == self.request.get('B'):
			self.response.out.write("done")
			return
		first = models.fromkey(self.request.get('A'))
		second = models.fromkey(self.request.get('B'))
		if first.state != "normal" or second.state != "normal":
			logging.info("State != normal")
			return
		firstset = dbtools.make_tupledict(first)
		secondset = dbtools.make_tupledict(second)
		self.simMatch = 0
		self.simTotal = 0
		for i in range(basics.USE_CHAIN_LENGTH):
			self.compare(firstset, secondset, i)
		dbtools.setSimilarity(first, second, float(self.simMatch)/self.simTotal)
		self.response.out.write("done")
예제 #4
0
파일: dbtools.py 프로젝트: adajw/Laura
def start_fingerprint(text, creator, parentkey):
	f = models.Fingerprint(
		state="normal",
		author = creator,
		parentprint = models.fromkey(parentkey),
		fulltext = text
	)
	f.put()
	doitlater.markovify(f)
	doitlater.compare(f)
	return f
예제 #5
0
파일: tq.py 프로젝트: adajw/Laura
	def post(self):
		''' Use a built response fingerprint to create a response
		string, then use it to actually respond.'''
		response_f = models.fromkey(self.request.get('key'))
		if response_f.build_count < response_f.build_count_target:
			logging.info(str(response_f.key()))
			logging.info("Not enough build_count (%d)" % response_f.build_count)
			self.error(500)
		else:
			r = markov.respond(response_f)
			if r != 1:
				logging.info("MARKOV CODE "+str(r))
				self.error(500)
예제 #6
0
파일: api.py 프로젝트: adajw/Laura
	def post(self):
		key = self.response.get('key')
		dbtools.cancel(models.fromkey(key))
		db.write('success')