z66x commited on
Commit
32d602f
·
1 Parent(s): 7daf359

joins all the json lyric files into a corpus

Browse files
Files changed (2) hide show
  1. rap_corpus.txt +0 -0
  2. tmp.py +46 -0
rap_corpus.txt ADDED
The diff for this file is too large to render. See raw diff
 
tmp.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+
4
+ input_folder = "rap_dataset"
5
+ output_file = "rap_corpus.txt"
6
+
7
+ total_songs = 0
8
+ total_chars = 0
9
+
10
+ print(f"Starting merge: reading from '{input_folder}' -> writing to '{output_file}'\n")
11
+
12
+ # Open the master output file once
13
+ with open(output_file, "w", encoding="utf-8") as f_out:
14
+
15
+ # Iterate through every JSON file in your dataset folder
16
+ for filename in os.listdir(input_folder):
17
+ if filename.endswith(".json"):
18
+ filepath = os.path.join(input_folder, filename)
19
+
20
+ try:
21
+ with open(filepath, "r", encoding="utf-8") as f_in:
22
+ artist_data = json.load(f_in)
23
+
24
+ # artist_data is a list of dictionaries based on your scraper
25
+ for song in artist_data:
26
+ lyrics = song.get("lyrics", "").strip()
27
+
28
+ if lyrics:
29
+ # Write lyrics followed by a double newline to separate songs
30
+ f_out.write(lyrics + "\n\n")
31
+
32
+ total_songs += 1
33
+ total_chars += len(lyrics)
34
+
35
+ print(f"Merged: {filename}")
36
+
37
+ except Exception as e:
38
+ print(f"Error processing {filename}: {e}")
39
+
40
+ print("\n" + "-"*30)
41
+ print("Corpus Merge Complete!")
42
+ print("-"*30)
43
+ print(f"Total songs merged: {total_songs}")
44
+ print(f"Total characters: {total_chars:,}")
45
+ print(f"Estimated words: {total_chars // 5:,} (assuming ~5 chars per word)")
46
+ print(f"Output saved to: {output_file}")