-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.java
79 lines (49 loc) · 2.07 KB
/
init.java
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
package UV_init;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class init {
static Map<String, String> artistMap = new HashMap<String, String>();// 存入变体ID和正确ID的映射
static List<String> list = new ArrayList<String>();// 存入清洗后的信息,一起写入磁盘中减少IO次数
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File artistsFile = new File("E:\\DATAdig-DATA\\artist_alias.txt");
BufferedReader bufferedReader = new BufferedReader(new FileReader(artistsFile));
String readString = "";
while ((readString = bufferedReader.readLine()) != null) {
String[] strings = readString.split("\t");
// if (strings.length == 2 && !strings[0].equals(""))
// System.out.print(strings[0] + " yy " + strings[1] + "\n");
artistMap.put(strings[0], strings[1]);
}
File file1 = new File("E:\\DATAdig-DATA\\artist_data.txt");
BufferedReader bufferedReader2 = new BufferedReader(new FileReader(file1));
String string = "";
int count = 0;
while ((string = bufferedReader2.readLine()) != null) {
String[] strings = string.split("\t");
// System.out.print(strings.length + "\n");
if (strings.length == 2 && artistMap.containsKey(strings[0])) {
count++;
String splic = artistMap.get(strings[0]) + "\t" + strings[1];
string = splic;
} else if (strings.length == 2) {
string = strings[0] + "\t" + strings[1];
}
if (strings.length == 2) {
list.add(string);
}
}
FileWriter fileWriter = new FileWriter(new File("E:\\DATAdig-DATA\\changed_artist_data.txt"));
for (int i = 0; i < list.size(); i++) {
fileWriter.write(list.get(i) + "\n");
}
System.out.println("count is " + count);
}
}