Beispiel #1
0
	def directed_graph(self) :
		if not hasattr(self, "_directed_graph") :
			print "getting directed graph ..."
			
			graph = defaultdict(_dd_int)
			# Zhu: in my VM, build speed is about 1.4w entity / s
			ac = AcoraBuilder(*self.database.entities).build()
			
			# match consumes no time, compared to build
			for text, attrib in self.database :
				entities = zip(*longest_match(ac.finditer(text)))[0]
				for entity in set(entities) :
					if entity == attrib["title"] :
						continue
					graph[attrib["title"]][entity] += 1
			
			delattr(self, "database")
			self._directed_graph = graph
			
		return self._directed_graph