-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCsvReader.java
58 lines (43 loc) · 2.25 KB
/
CsvReader.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
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
//https://mvnrepository.com/artifact/au.com.bytecode/opencsv/2.4
import au.com.bytecode.opencsv.CSVReader;
public class CsvReader {
//Here you should write the file name of the CSV input file and the NT output file
//In case CSV file is too large, you could divide the output file to 2 parts by specifying the middle of the file
public static String OutputNtFileNamePart1= "summary-organization-part1.nt";
public static String OutputNtFileNamePart2= "summary-organization-part2.nt";
public static String inputCsvFileName= "organizations.csv";
public static int midDataRow=300000;
public static void main(String[] args) throws IOException {
File fout1 = new File(OutputNtFileNamePart1);
FileOutputStream fos1 = new FileOutputStream(fout1);
BufferedWriter bw1 = new BufferedWriter(new OutputStreamWriter(fos1));
File fout2 = new File(OutputNtFileNamePart2);
FileOutputStream fos2 = new FileOutputStream(fout2);
BufferedWriter bw2 = new BufferedWriter(new OutputStreamWriter(fos2));
//The library for CSV reader should be added from https://mvnrepository.com/artifact/au.com.bytecode/opencsv/2.4
CSVReader reader = new CSVReader(new FileReader(inputCsvFileName));
String [] nextLine;
int i=0;
while ((nextLine = reader.readNext()) != null) {
if(i<midDataRow) {
// nextLine[] is an array of the CSV columns per line
//If you are creating CSV file for Organization or People, select Permalink column. If other entity types, the UUID column should be selected in nextLine[COLUMN NUMBER]
bw1.write("<http://linked-crunchbase.org/api"+nextLine[1]+"#id> <http://linked-crunchbase.org/api-vocab#api_path> <http://linked-crunchbase.org/api"+nextLine[1]+"?items_per_page=250> .");
bw1.newLine();
i++;
}
else {
bw2.write("<http://linked-crunchbase.org/api"+nextLine[1]+"#id> <http://linked-crunchbase.org/api-vocab#api_path> <http://linked-crunchbase.org/api"+nextLine[1]+"?items_per_page=250> .");
bw2.newLine();
}
}
bw1.close();
bw2.close();
}
}