File size: 7,041 Bytes
db5855f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Season"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "s01\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "\n",
    "# read the JSON file from the web\n",
    "json_file = 'https://raw.githubusercontent.com/emorynlp/character-mining/master/json/friends_season_01.json'\n",
    "r = requests.get(json_file)\n",
    "\n",
    "# load season 1\n",
    "season = json.loads(r.text)\n",
    "season_id = season['season_id']\n",
    "print(season_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Episodes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "s01_e01\n",
      "s01_e02\n",
      "s01_e03\n",
      "s01_e04\n",
      "s01_e05\n",
      "s01_e06\n",
      "s01_e07\n",
      "s01_e08\n",
      "s01_e09\n",
      "s01_e10\n",
      "s01_e11\n",
      "s01_e12\n",
      "s01_e13\n",
      "s01_e14\n",
      "s01_e15\n",
      "s01_e16\n",
      "s01_e17\n",
      "s01_e18\n",
      "s01_e19\n",
      "s01_e20\n",
      "s01_e21\n",
      "s01_e22\n",
      "s01_e23\n",
      "s01_e24\n"
     ]
    }
   ],
   "source": [
    "# retrieve episodes\n",
    "episodes = season['episodes']\n",
    "\n",
    "# iterate through the episodes\n",
    "for episode in episodes:\n",
    "    episode_id = episode['episode_id']\n",
    "    print(episode_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Scenes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "s01_e18_c01\n",
      "s01_e18_c02\n",
      "s01_e18_c03\n",
      "s01_e18_c04\n",
      "s01_e18_c05\n",
      "s01_e18_c06\n",
      "s01_e18_c07\n",
      "s01_e18_c08\n"
     ]
    }
   ],
   "source": [
    "# retrive scenes from the 18th episode\n",
    "episode = episodes[17]\n",
    "scenes = episode['scenes']\n",
    "\n",
    "# iterate through the scenes\n",
    "for scene in scenes:\n",
    "    scene_id = scene['scene_id']\n",
    "    print(scene_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Utterances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "s01_e18_c05_u001\n",
      "s01_e18_c05_u002\n",
      "s01_e18_c05_u003\n",
      "s01_e18_c05_u004\n",
      "s01_e18_c05_u005\n",
      "s01_e18_c05_u006\n",
      "s01_e18_c05_u007\n",
      "s01_e18_c05_u008\n",
      "s01_e18_c05_u009\n",
      "s01_e18_c05_u010\n",
      "s01_e18_c05_u011\n",
      "s01_e18_c05_u012\n",
      "s01_e18_c05_u013\n",
      "s01_e18_c05_u014\n",
      "s01_e18_c05_u015\n",
      "s01_e18_c05_u016\n",
      "s01_e18_c05_u017\n",
      "s01_e18_c05_u018\n",
      "s01_e18_c05_u019\n",
      "s01_e18_c05_u020\n",
      "s01_e18_c05_u021\n",
      "s01_e18_c05_u022\n"
     ]
    }
   ],
   "source": [
    "# retrieve utterances from the 5th scene\n",
    "scene = scenes[4]\n",
    "utterances = scene['utterances']\n",
    "\n",
    "# iterate through the utterances\n",
    "for utterance in utterances:\n",
    "    utterance_id = utterance['utterance_id']\n",
    "    print(utterance_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Utterance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Phoebe Buffay', 'Rachel Green']\n",
      "Yes, we should. I think we should.\n",
      "[['Yes', ',', 'we', 'should', '.'], ['I', 'think', 'we', 'should', '.']]\n"
     ]
    }
   ],
   "source": [
    "# retrive fields from the 18th utterance\n",
    "utterance = utterances[17]\n",
    "\n",
    "# list of speakers\n",
    "speakers = utterance['speakers']\n",
    "print(speakers)\n",
    "\n",
    "# the original transcript\n",
    "transcript = utterance['transcript']\n",
    "print(transcript)\n",
    "\n",
    "# list of sentences, where each sentence is a list of tokens\n",
    "tokens = utterance['tokens']\n",
    "print(tokens)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For seasons 6-9, caption information is available."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Begin time in milliseconds: 6923\n",
      "End time in milliseconds: 8382\n",
      "Text: you sure you wanna do this\n"
     ]
    }
   ],
   "source": [
    "# load season 6\n",
    "json_file = 'https://raw.githubusercontent.com/emorynlp/character-mining/master/json/friends_season_06.json'\n",
    "r = requests.get(json_file)\n",
    "season = json.loads(r.text)\n",
    "\n",
    "# 1st episode, 1st scene, 3rd utterance\n",
    "utterance = season['episodes'][0]['scenes'][0]['utterances'][2]\n",
    "caption = utterance['caption']\n",
    "\n",
    "print('Begin time in milliseconds: %d' % caption[0])\n",
    "print('End time in milliseconds: %d' % caption[1])\n",
    "print('Text: %s' % caption[2])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}