예제 #1
0
	def getFirstOrderKeywords(self):
		keywords = []
		# for each |question| in full test, get keywords
		for i, question in enumerate(self.test):
			print('Getting keyword for Q{}'.format(i))
			if self.dataType == 'val':
				questionText, answers = question
			else:
				questionText, answers, correctAnswer = question
			keywords += util.getKeywords(questionText)
			for ans in answers:
				keywords += util.getKeywords(ans)
		return list(set(keywords))
예제 #2
0
	def __init__(self, question, N):
		# print('Question:', question)
		self.graph = {}
		self.N = N
		self.questionKeywords = util.getKeywords(question)
		# print('Question keywords extracted:', self.questionKeywords)

		self.importance = {kw: 1/len(self.questionKeywords) for kw in self.questionKeywords}
		# self.importance = util.getImportanceDict(question)
		# print('Keyword importance:', self.importance)

		self.secondOrderKeywords = localKeywords[question] if question in localKeywords else self.bestWords()
		
		initialWords = self.secondOrderKeywords + self.questionKeywords
		# print('Nodes are:', initialWords)

		for word in initialWords:
			self.addWord(word)
예제 #3
0
	def getAnswerScore(self, answer):
		''' |answer| is a string '''

		self.answerKeywords = util.getKeywords(answer)
		if len(self.answerKeywords) == 0:
			return 0
		for keyword in self.answerKeywords:
			self.addWord(keyword)
		self.pruneGraph()

		finalScore = 0
		for keyword in self.answerKeywords:
			finalScore += self.coherenceScore(keyword)
		# print('For answer {}, final score is {}'.format(answer, finalScore))

		# Get search metric
		# searchScore = util.getAnswerCost(self)
		# print('Search score: {}'.format(searchScore))
		return finalScore #, searchScore
예제 #4
0
	def takeTestW2V(self):
		self.reset()
		for num, question in enumerate(self.test):
			start = time.time()

			questionText, answers, correctAnswer = question
			keywords = util.getKeywords(questionText)

			# Get scores for each answer
			answerScores = []
			for answer in answers:
				answerScores.append(util.averageSimilarity(keywords, answer))

			index = answerScores.index(max(answerScores))
			if self.LETTERS[index] == correctAnswer:
				self.correct += 1
			else:
				self.incorrect += 1
			end = time.time()

			self.answerReport.append((answerScores, index, correctAnswer))
			self.timeReport.append(end - start)