def test_symbols(self): self.assertEqual(ed.symbols(('is', 'graphbrain/1', 'great/1')), {'is', 'graphbrain/1', 'great/1'}) self.assertEqual( ed.symbols( ('src', 'graphbrain/2', ('is', 'graphbrain/1', 'great/1'))), {'is', 'graphbrain/1', 'great/1', 'src', 'graphbrain/2'}) self.assertEqual(ed.symbols('graphbrain/1'), {'graphbrain/1'})
def ego(self, center): """Returns all symbols directly connected to centre by hyperedges.""" logging.debug('[hypergraph ego()] %s' % ed.edge2str(center)) edges = self.star(center) symbols = set() for edge in edges: for symbol in ed.symbols(edge): symbols.add(symbol) return symbols
def words_around_symbol(self, symbol): start = time.time() edges = self.hg.star(symbol, limit=STAR_LIMIT) words = set() for edge in edges: for entity in edge: for symbol in ed.symbols(entity): term = sym.symbol2str(symbol) for token in term.split(): word = self.parser.make_word(token) if word.prob < MAX_PROB and np.count_nonzero( word.vector) > 0: words.add(word) self.words_around_symbol_t += time.time() - start return words