闪瞎你双眼的代码

import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;

import java.util.HashMap;
import java.util.Map;

public class test1101 {
static int num = 0;
public static void main(String[] args) throws Exception{
String filePath="./data/entitytest_1104.csv";//文件结果路径
String readPath="./data/ownthink_v2.csv";//读取的文件路径
String finalPath = “./data/finalFile_1104”;
CsvReader csvReader = new CsvReader(readPath);

    CsvWriter csvWriter = new CsvWriter(filePath);
    CsvWriter finCsvWriter = new CsvWriter(finalPath);


    Map map = new HashMap();

    String[] header = {":ID","name",":LABLE"};
    csvWriter.writeRecord(header);

    String[] header2 = {":START_ID","name",":END_ID",":TYPE"};
    finCsvWriter.writeRecord(header2);

    csvReader.readRecord();
    while (csvReader.readRecord()) {
        String key = csvReader.get(0);
        if (null == map.get(key)) {
            String[] body1 = {"entity" + num, key, "ENTITY"};
            csvWriter.writeRecord(body1);
            map.put(key,"entity" + num);
            num++;
        }
        String name = csvReader.get(2);
        if (null == map.get(name)) {
            String[] body2 = {"entity" + num, name, "ENTITY1"};
            csvWriter.writeRecord(body2);
            map.put(name, "entity" + num);
            num++;
        }

        String id_1 = map.get(key);
        String id_2 = map.get(name);
        String[] body3 = {id_1,csvReader.get(1),id_2,"RELATIONSHIP"};
        finCsvWriter.writeRecord(body3);
    }

    csvWriter.close();
    finCsvWriter.close();
    csvReader.close();
}

}

你可能感兴趣的:(闪瞎你双眼的代码)