How to use the pyahocorasick.nil function in pyahocorasick

To help you get started, we’ve selected a few pyahocorasick examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WojciechMula / pyahocorasick / py / exportdot.py View on Github external
def walk(node):
		queue = [node]
		while queue:
			node = queue.pop()
			yield node

			for child in node.children.itervalues():
				if child != node:
					queue.append(child)

	nodes = list(walk(trie.root))

	# nodes
	for node in nodes:
		if node.output != pyahocorasick.nil:
			writeln("\tnode%d [shape=doublecircle, label=\"\"]" % id(node))
		else:
			writeln("\tnode%d [shape=circle, label=\"\"]" % id(node))

	# trie edges
	for node in nodes:
		for letter, child in node.children.iteritems():
			nodeid = id(node)
			destid = id(child)
			if destid == id(trie.root):
				# do not show self-links of root node created during make_automaton
				continue

			if letter.isalnum():
				label = letter
			else:

pyahocorasick

pyahocorasick is a fast and memory efficient library for exact or approximate multi-pattern string search. With the ``ahocorasick.Automaton`` class, you can find multiple key string occurrences at once in some input text. You can use it as a plain dict-like Trie or convert a Trie to an automaton for efficient Aho-Corasick search. And pickle to disk for easy reuse of large automatons. Implemented in C and tested on Python 3.6+. Works on Linux, macOS and Windows. BSD-3-Cause license.

BSD-3-Clause
Latest version published 9 months ago

Package Health Score

78 / 100
Full package analysis

Popular pyahocorasick functions