Пример #1
0
	def bestWords(self):
		'''Returns best N * num_keywords 1st order links 
		to question keywords'''
		words = []
		for keyword in self.questionKeywords:
			neighbors = util.getRelations(keyword)
			for nbr in neighbors:
				if nbr not in words:
					words.append(nbr)
		words = sorted(words, key=self.relevanceScore)
		words.reverse()
		limit = len(self.questionKeywords) * self.N

		return words[0 : limit + 1]
Пример #2
0
	def addWord(self, w):
		''' Takes in word |w| and adds it to current graph,
		making all appropriate links to existing graph '''
		# if w in self.graph:
		# 	print('{} already in graph with {} connections'.format(w, len(self.graph[w])))
		if w not in self.graph: self.graph[w] = []

		possibleNeighbors = util.getRelations(w)
		counter = 0
		for node in self.graph:
			if node in possibleNeighbors:
				# Add relations only if they don't already exist
				if node not in self.graph[w]:
					self.graph[w] += [node]
					counter += 1
				if w not in self.graph[node]:
					self.graph[node] += [w]
Пример #3
0
def testGetRelations(w):
	neighbors = util.getRelations(w)
	print(len(neighbors))
	return neighbors