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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "8a13cfae",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"data": {
|
11 |
+
"application/vnd.jupyter.widget-view+json": {
|
12 |
+
"model_id": "5837401d683f4cda99521aaad9baa6f6",
|
13 |
+
"version_major": 2,
|
14 |
+
"version_minor": 0
|
15 |
+
},
|
16 |
+
"text/plain": [
|
17 |
+
"sermons: 0%| | 0/46 [00:00<?, ?it/s]"
|
18 |
+
]
|
19 |
+
},
|
20 |
+
"metadata": {},
|
21 |
+
"output_type": "display_data"
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"name": "stdout",
|
25 |
+
"output_type": "stream",
|
26 |
+
"text": [
|
27 |
+
"/Volumes/MM/autoThread_old/churches/._all-souls_org.json 'utf-8' codec can't decode byte 0xb0 in position 37: invalid start byte\n",
|
28 |
+
"45 files\n"
|
29 |
+
]
|
30 |
+
}
|
31 |
+
],
|
32 |
+
"source": [
|
33 |
+
"from tqdm.notebook import tqdm\n",
|
34 |
+
"from pathlib import Path\n",
|
35 |
+
"import json\n",
|
36 |
+
"import pandas as pd\n",
|
37 |
+
"\n",
|
38 |
+
"\n",
|
39 |
+
"source = Path('/Volumes/MM/autoThread_old/churches/')\n",
|
40 |
+
"data = []\n",
|
41 |
+
"folder = Path(source).glob('*.json')\n",
|
42 |
+
"for _file in tqdm(folder, total=len(list(Path(source).glob('*.json'))), desc='sermons'):\n",
|
43 |
+
" try:\n",
|
44 |
+
" with open(_file, 'r') as f:\n",
|
45 |
+
" docs = json.load(f) # {MP3file : {\"text\" ... }}\n",
|
46 |
+
" except Exception as e:\n",
|
47 |
+
" print(_file, e)\n",
|
48 |
+
" continue\n",
|
49 |
+
" church = _file.stem\n",
|
50 |
+
" updocs = {}\n",
|
51 |
+
" for k,v in docs.items():\n",
|
52 |
+
" v['church'] = church\n",
|
53 |
+
" updocs[k] = v\n",
|
54 |
+
" data.append( updocs )\n",
|
55 |
+
"print(len(data), 'files')"
|
56 |
+
]
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"cell_type": "code",
|
60 |
+
"execution_count": 2,
|
61 |
+
"id": "705968c8",
|
62 |
+
"metadata": {},
|
63 |
+
"outputs": [
|
64 |
+
{
|
65 |
+
"data": {
|
66 |
+
"text/html": [
|
67 |
+
"<div>\n",
|
68 |
+
"<style scoped>\n",
|
69 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
70 |
+
" vertical-align: middle;\n",
|
71 |
+
" }\n",
|
72 |
+
"\n",
|
73 |
+
" .dataframe tbody tr th {\n",
|
74 |
+
" vertical-align: top;\n",
|
75 |
+
" }\n",
|
76 |
+
"\n",
|
77 |
+
" .dataframe thead th {\n",
|
78 |
+
" text-align: right;\n",
|
79 |
+
" }\n",
|
80 |
+
"</style>\n",
|
81 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
82 |
+
" <thead>\n",
|
83 |
+
" <tr style=\"text-align: right;\">\n",
|
84 |
+
" <th></th>\n",
|
85 |
+
" <th>church</th>\n",
|
86 |
+
" <th>source</th>\n",
|
87 |
+
" <th>text</th>\n",
|
88 |
+
" <th>sentences</th>\n",
|
89 |
+
" <th>processing_time</th>\n",
|
90 |
+
" <th>transcription_errors</th>\n",
|
91 |
+
" <th>duration(s)</th>\n",
|
92 |
+
" </tr>\n",
|
93 |
+
" </thead>\n",
|
94 |
+
" <tbody>\n",
|
95 |
+
" <tr>\n",
|
96 |
+
" <th>1.1</th>\n",
|
97 |
+
" <td>all-souls_org</td>\n",
|
98 |
+
" <td>04.02.22ILeftMyHeartInSF.mp3</td>\n",
|
99 |
+
" <td>Our reading this morning. Is from the same scr...</td>\n",
|
100 |
+
" <td>177</td>\n",
|
101 |
+
" <td>327.6</td>\n",
|
102 |
+
" <td>26</td>\n",
|
103 |
+
" <td>1528.2</td>\n",
|
104 |
+
" </tr>\n",
|
105 |
+
" <tr>\n",
|
106 |
+
" <th>1.2</th>\n",
|
107 |
+
" <td>all-souls_org</td>\n",
|
108 |
+
" <td>04.02.15AfraidOfTheDark.mp3</td>\n",
|
109 |
+
" <td>Mornings readings are. 2 and brief. The first ...</td>\n",
|
110 |
+
" <td>123</td>\n",
|
111 |
+
" <td>139.6</td>\n",
|
112 |
+
" <td>6</td>\n",
|
113 |
+
" <td>697.2</td>\n",
|
114 |
+
" </tr>\n",
|
115 |
+
" <tr>\n",
|
116 |
+
" <th>1.3</th>\n",
|
117 |
+
" <td>all-souls_org</td>\n",
|
118 |
+
" <td>03.01.26AwesomeMeetsTheFamiliar.mp3</td>\n",
|
119 |
+
" <td>It is a great joy and privilege for me to be h...</td>\n",
|
120 |
+
" <td>269</td>\n",
|
121 |
+
" <td>323.8</td>\n",
|
122 |
+
" <td>5</td>\n",
|
123 |
+
" <td>1443.6</td>\n",
|
124 |
+
" </tr>\n",
|
125 |
+
" <tr>\n",
|
126 |
+
" <th>1.4</th>\n",
|
127 |
+
" <td>all-souls_org</td>\n",
|
128 |
+
" <td>04.02.11WhatGoodIsGod.mp3</td>\n",
|
129 |
+
" <td>I've told many of you how excited i am to have...</td>\n",
|
130 |
+
" <td>125</td>\n",
|
131 |
+
" <td>367.6</td>\n",
|
132 |
+
" <td>3</td>\n",
|
133 |
+
" <td>1387.1</td>\n",
|
134 |
+
" </tr>\n",
|
135 |
+
" <tr>\n",
|
136 |
+
" <th>1.5</th>\n",
|
137 |
+
" <td>all-souls_org</td>\n",
|
138 |
+
" <td>04.02.29ConspiracyAgainstVu.mp3</td>\n",
|
139 |
+
" <td>Some of you may have thought that. Service wou...</td>\n",
|
140 |
+
" <td>198</td>\n",
|
141 |
+
" <td>280.8</td>\n",
|
142 |
+
" <td>7</td>\n",
|
143 |
+
" <td>1248.1</td>\n",
|
144 |
+
" </tr>\n",
|
145 |
+
" <tr>\n",
|
146 |
+
" <th>...</th>\n",
|
147 |
+
" <td>...</td>\n",
|
148 |
+
" <td>...</td>\n",
|
149 |
+
" <td>...</td>\n",
|
150 |
+
" <td>...</td>\n",
|
151 |
+
" <td>...</td>\n",
|
152 |
+
" <td>...</td>\n",
|
153 |
+
" <td>...</td>\n",
|
154 |
+
" </tr>\n",
|
155 |
+
" <tr>\n",
|
156 |
+
" <th>45.470</th>\n",
|
157 |
+
" <td>uufvb_org</td>\n",
|
158 |
+
" <td>2012Mar18Sermon32.mp3</td>\n",
|
159 |
+
" <td>30 years old. Person. Usefulness. By the time ...</td>\n",
|
160 |
+
" <td>302</td>\n",
|
161 |
+
" <td>209.8</td>\n",
|
162 |
+
" <td>4</td>\n",
|
163 |
+
" <td>913.2</td>\n",
|
164 |
+
" </tr>\n",
|
165 |
+
" <tr>\n",
|
166 |
+
" <th>45.471</th>\n",
|
167 |
+
" <td>uufvb_org</td>\n",
|
168 |
+
" <td>2015Feb22Sermon128.mp3</td>\n",
|
169 |
+
" <td>Good morning everyone is glad to be 80° today ...</td>\n",
|
170 |
+
" <td>632</td>\n",
|
171 |
+
" <td>450.8</td>\n",
|
172 |
+
" <td>20</td>\n",
|
173 |
+
" <td>1885.9</td>\n",
|
174 |
+
" </tr>\n",
|
175 |
+
" <tr>\n",
|
176 |
+
" <th>45.472</th>\n",
|
177 |
+
" <td>uufvb_org</td>\n",
|
178 |
+
" <td>2011Jul24Sermon32.mp3</td>\n",
|
179 |
+
" <td>4 years ago. As my partner charlie and i were ...</td>\n",
|
180 |
+
" <td>405</td>\n",
|
181 |
+
" <td>295.8</td>\n",
|
182 |
+
" <td>5</td>\n",
|
183 |
+
" <td>1386.5</td>\n",
|
184 |
+
" </tr>\n",
|
185 |
+
" <tr>\n",
|
186 |
+
" <th>45.473</th>\n",
|
187 |
+
" <td>uufvb_org</td>\n",
|
188 |
+
" <td>2015Feb15Sermon32.mp3</td>\n",
|
189 |
+
" <td>Good morning. Welcome to the unitarian univers...</td>\n",
|
190 |
+
" <td>472</td>\n",
|
191 |
+
" <td>345.6</td>\n",
|
192 |
+
" <td>18</td>\n",
|
193 |
+
" <td>1592.7</td>\n",
|
194 |
+
" </tr>\n",
|
195 |
+
" <tr>\n",
|
196 |
+
" <th>45.474</th>\n",
|
197 |
+
" <td>uufvb_org</td>\n",
|
198 |
+
" <td>2010Dec12Sermon128.mp3</td>\n",
|
199 |
+
" <td>I shared the words of bill mckibben with joyce...</td>\n",
|
200 |
+
" <td>463</td>\n",
|
201 |
+
" <td>225.5</td>\n",
|
202 |
+
" <td>411</td>\n",
|
203 |
+
" <td>1339.5</td>\n",
|
204 |
+
" </tr>\n",
|
205 |
+
" </tbody>\n",
|
206 |
+
"</table>\n",
|
207 |
+
"<p>6900 rows × 7 columns</p>\n",
|
208 |
+
"</div>"
|
209 |
+
],
|
210 |
+
"text/plain": [
|
211 |
+
" church source \\\n",
|
212 |
+
"1.1 all-souls_org 04.02.22ILeftMyHeartInSF.mp3 \n",
|
213 |
+
"1.2 all-souls_org 04.02.15AfraidOfTheDark.mp3 \n",
|
214 |
+
"1.3 all-souls_org 03.01.26AwesomeMeetsTheFamiliar.mp3 \n",
|
215 |
+
"1.4 all-souls_org 04.02.11WhatGoodIsGod.mp3 \n",
|
216 |
+
"1.5 all-souls_org 04.02.29ConspiracyAgainstVu.mp3 \n",
|
217 |
+
"... ... ... \n",
|
218 |
+
"45.470 uufvb_org 2012Mar18Sermon32.mp3 \n",
|
219 |
+
"45.471 uufvb_org 2015Feb22Sermon128.mp3 \n",
|
220 |
+
"45.472 uufvb_org 2011Jul24Sermon32.mp3 \n",
|
221 |
+
"45.473 uufvb_org 2015Feb15Sermon32.mp3 \n",
|
222 |
+
"45.474 uufvb_org 2010Dec12Sermon128.mp3 \n",
|
223 |
+
"\n",
|
224 |
+
" text sentences \\\n",
|
225 |
+
"1.1 Our reading this morning. Is from the same scr... 177 \n",
|
226 |
+
"1.2 Mornings readings are. 2 and brief. The first ... 123 \n",
|
227 |
+
"1.3 It is a great joy and privilege for me to be h... 269 \n",
|
228 |
+
"1.4 I've told many of you how excited i am to have... 125 \n",
|
229 |
+
"1.5 Some of you may have thought that. Service wou... 198 \n",
|
230 |
+
"... ... ... \n",
|
231 |
+
"45.470 30 years old. Person. Usefulness. By the time ... 302 \n",
|
232 |
+
"45.471 Good morning everyone is glad to be 80° today ... 632 \n",
|
233 |
+
"45.472 4 years ago. As my partner charlie and i were ... 405 \n",
|
234 |
+
"45.473 Good morning. Welcome to the unitarian univers... 472 \n",
|
235 |
+
"45.474 I shared the words of bill mckibben with joyce... 463 \n",
|
236 |
+
"\n",
|
237 |
+
" processing_time transcription_errors duration(s) \n",
|
238 |
+
"1.1 327.6 26 1528.2 \n",
|
239 |
+
"1.2 139.6 6 697.2 \n",
|
240 |
+
"1.3 323.8 5 1443.6 \n",
|
241 |
+
"1.4 367.6 3 1387.1 \n",
|
242 |
+
"1.5 280.8 7 1248.1 \n",
|
243 |
+
"... ... ... ... \n",
|
244 |
+
"45.470 209.8 4 913.2 \n",
|
245 |
+
"45.471 450.8 20 1885.9 \n",
|
246 |
+
"45.472 295.8 5 1386.5 \n",
|
247 |
+
"45.473 345.6 18 1592.7 \n",
|
248 |
+
"45.474 225.5 411 1339.5 \n",
|
249 |
+
"\n",
|
250 |
+
"[6900 rows x 7 columns]"
|
251 |
+
]
|
252 |
+
},
|
253 |
+
"execution_count": 2,
|
254 |
+
"metadata": {},
|
255 |
+
"output_type": "execute_result"
|
256 |
+
}
|
257 |
+
],
|
258 |
+
"source": [
|
259 |
+
"# rows are (church, MP3): cols are text, etc.\n",
|
260 |
+
"vals = []\n",
|
261 |
+
"ids = []\n",
|
262 |
+
"for idx,item in enumerate(data):\n",
|
263 |
+
" _id = 1\n",
|
264 |
+
" for mp3,val in item.items():\n",
|
265 |
+
" vals.append(val) # dict with text, time, sent, errors, dur, file(name)\n",
|
266 |
+
" ids.append(f\"{idx+1}.{_id}\")\n",
|
267 |
+
" _id += 1\n",
|
268 |
+
"df = pd.DataFrame(data=vals, columns=['church', 'file', 'text', 'sentences', 'processing_time', 'errors', 'duration'], index=ids)\n",
|
269 |
+
"df.duration = df.duration.round(1)\n",
|
270 |
+
"df = df.rename(columns={'duration': 'duration(s)', 'file':'source', 'errors':'transcription_errors'})\n",
|
271 |
+
"df.to_csv(\"unitarian-universalist-church-sermons-n=6900b.csv\")\n",
|
272 |
+
"df"
|
273 |
+
]
|
274 |
+
},
|
275 |
+
{
|
276 |
+
"cell_type": "code",
|
277 |
+
"execution_count": null,
|
278 |
+
"id": "fd50088f",
|
279 |
+
"metadata": {},
|
280 |
+
"outputs": [],
|
281 |
+
"source": []
|
282 |
+
}
|
283 |
+
],
|
284 |
+
"metadata": {
|
285 |
+
"kernelspec": {
|
286 |
+
"display_name": "Python 3",
|
287 |
+
"language": "python",
|
288 |
+
"name": "python3"
|
289 |
+
},
|
290 |
+
"language_info": {
|
291 |
+
"codemirror_mode": {
|
292 |
+
"name": "ipython",
|
293 |
+
"version": 3
|
294 |
+
},
|
295 |
+
"file_extension": ".py",
|
296 |
+
"mimetype": "text/x-python",
|
297 |
+
"name": "python",
|
298 |
+
"nbconvert_exporter": "python",
|
299 |
+
"pygments_lexer": "ipython3",
|
300 |
+
"version": "3.9.12"
|
301 |
+
}
|
302 |
+
},
|
303 |
+
"nbformat": 4,
|
304 |
+
"nbformat_minor": 5
|
305 |
+
}
|