MCPcopy Create free account
hub / github.com/chinawithfrank/ChatBotCourse / feed

Method feed

subtitle/preprocess/langconv.py:118–171  ·  view source on GitHub ↗
(self, char, map)

Source from the content-addressed store, hash-verified

116 return new
117
118 def feed(self, char, map):
119 node = map[self.pool+char]
120
121 if node.have_child:
122 if node.is_tail:
123 if node.is_original:
124 cond = UNMATCHED_SWITCH
125 else:
126 cond = MATCHED_SWITCH
127 else:
128 cond = CONNECTOR
129 else:
130 if node.is_tail:
131 cond = TAIL
132 else:
133 cond = ERROR
134
135 new = None
136 if cond == ERROR:
137 self.state = FAIL
138 elif cond == TAIL:
139 if self.state == WAIT_TAIL and node.is_original_long_word():
140 self.state = FAIL
141 else:
142 self.final += node.to_word
143 self.len += 1
144 self.pool = UEMPTY
145 self.state = END
146 elif self.state == START or self.state == WAIT_TAIL:
147 if cond == MATCHED_SWITCH:
148 new = self.clone(node.from_word)
149 self.final += node.to_word
150 self.len += 1
151 self.state = END
152 self.pool = UEMPTY
153 elif cond == UNMATCHED_SWITCH or cond == CONNECTOR:
154 if self.state == START:
155 new = self.clone(node.from_word)
156 self.final += node.to_word
157 self.len += 1
158 self.state = END
159 else:
160 if node.is_follow(self.pool):
161 self.state = FAIL
162 else:
163 self.pool = node.from_word
164 elif self.state == END:
165 # END is a new START
166 self.state = START
167 new = self.feed(char, map)
168 elif self.state == FAIL:
169 raise StatesMachineException('Translate States Machine '
170 'have error with input data %s' % node)
171 return new
172
173 def __len__(self):
174 return self.len + 1

Callers

nothing calls this directly

Calls 4

cloneMethod · 0.95
is_original_long_wordMethod · 0.80
is_followMethod · 0.80

Tested by

no test coverage detected