MCPcopy
hub / github.com/codemayq/chinese-chatbot-corpus / feed

Method feed

language/langconv.py:121–174  ·  view source on GitHub ↗
(self, char, map)

Source from the content-addressed store, hash-verified

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