-
Notifications
You must be signed in to change notification settings - Fork 0
/
SongOld.pde
59 lines (48 loc) · 1.49 KB
/
SongOld.pde
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
class SongOld{
String title;
String[] lyrics;
public SongOld(String title, String[] lines) {
this.title = title;
setLyricsFromLines(lines);
}
public void setLyricsFromLines(String[] lines) {
ArrayList<String> temp = new ArrayList<String>();
for (String line : lines) {
for (String word : line.split(" ")) {
if (word.trim().isEmpty() || word.startsWith("[") || word.endsWith("]"))
continue;
else
temp.add(cleanAndFormat(word));
}
}
lyrics = new String[temp.size()];
for (int i = 0; i < lyrics.length; i++) {
lyrics[i] = temp.get(i);
}
// ugly-ass code right there
}
public String getTitle() { return title; }
public String[] getLyrics() { return lyrics; }
public String getLyricsAsString() {
return Arrays.toString(lyrics);
}
public ArrayList<Word> getLyricFreqs() {
ArrayList<Word> out = new ArrayList<Word>();
for (String lyric : lyrics) {
Word newWord = new Word(lyric);
if (!out.contains(newWord)) {
out.add(newWord);
// println("adding " + newWord);
}
else {
out.get(out.indexOf(newWord)).inc();
// println("inc " + newWord);
}
//print(out.get(out.indexOf(newWord)).getFreq());
}
return out;
}
private String cleanAndFormat(String word) {
return word.replaceAll("[^a-zA-z&&[^'&&[\\D]]]","").toLowerCase();
}
}