MCPcopy Index your code
hub / github.com/pytorch/tutorials / loadLinesAndConversations

Function loadLinesAndConversations

beginner_source/chatbot_tutorial.py:171–195  ·  view source on GitHub ↗
(fileName)

Source from the content-addressed store, hash-verified

169
170# Splits each line of the file to create lines and conversations
171def loadLinesAndConversations(fileName):
172 lines = {}
173 conversations = {}
174 with open(fileName, 'r', encoding='iso-8859-1') as f:
175 for line in f:
176 lineJson = json.loads(line)
177 # Extract fields for line object
178 lineObj = {}
179 lineObj["lineID"] = lineJson["id"]
180 lineObj["characterID"] = lineJson["speaker"]
181 lineObj["text"] = lineJson["text"]
182 lines[lineObj['lineID']] = lineObj
183
184 # Extract fields for conversation object
185 if lineJson["conversation_id"] not in conversations:
186 convObj = {}
187 convObj["conversationID"] = lineJson["conversation_id"]
188 convObj["movieID"] = lineJson["meta"]["movie_id"]
189 convObj["lines"] = [lineObj]
190 else:
191 convObj = conversations[lineJson["conversation_id"]]
192 convObj["lines"].insert(0, lineObj)
193 conversations[convObj["conversationID"]] = convObj
194
195 return lines, conversations
196
197
198# Extracts pairs of sentences from conversations

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected