MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / add_keyword

Method add_keyword

strings/aho_corasick.py:23–40  ·  view source on GitHub ↗
(self, keyword: str)

Source from the content-addressed store, hash-verified

21 return None
22
23 def add_keyword(self, keyword: str) -> None:
24 current_state = 0
25 for character in keyword:
26 next_state = self.find_next_state(current_state, character)
27 if next_state is None:
28 self.adlist.append(
29 {
30 "value": character,
31 "next_states": [],
32 "fail_state": 0,
33 "output": [],
34 }
35 )
36 self.adlist[current_state]["next_states"].append(len(self.adlist) - 1)
37 current_state = len(self.adlist) - 1
38 else:
39 current_state = next_state
40 self.adlist[current_state]["output"].append(keyword)
41
42 def set_fail_transitions(self) -> None:
43 q: deque = deque()

Callers 1

__init__Method · 0.95

Calls 2

find_next_stateMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected