Java Code Examples for com.csvreader.CsvReader#setDelimiter()

The following examples show how to use com.csvreader.CsvReader#setDelimiter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public static MLDouble readMDoubleFromCSVFile(Path inFilePath, String mName, int nrows, int ncols, char delimiter) throws NumberFormatException, IOException {
    MLDouble mlDouble = new MLDouble(mName, new int[] {nrows, ncols});
    CsvReader cvsReader = new CsvReader(inFilePath.toString());
    cvsReader.setDelimiter(delimiter);
    int i = 0;
    while (cvsReader.readRecord()) {
        String[] rows = cvsReader.getValues();
        int j = 0;
        for (String col : rows) {
            mlDouble.set(new Double(col), i, j);
            j++;
        }
        i++;
    }
    return mlDouble;
}
 
Example 2
Source File: Utils.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public static double[][] readDoubleMatrixFromCSVFile(Path inFilePath, int nrows, int ncols, char delimiter) throws NumberFormatException, IOException {
    double[][] mlDouble = new double[nrows][ncols];
    CsvReader cvsReader = new CsvReader(inFilePath.toString());
    cvsReader.setDelimiter(delimiter);
    int i = 0;
    while (cvsReader.readRecord()) {
        String[] rows = cvsReader.getValues();
        int j = 0;
        for (String col : rows) {
            mlDouble[i][j] = Double.parseDouble(col);
            j++;
            if (j >= ncols) {
                break;
            }
        }
        i++;
        if (i >= nrows) {
            break;
        }

    }
    return mlDouble;
}
 
Example 3
Source File: Utils.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public static double[] readDoubleArrayFromCSVFile(Path inFilePath,  int nrows, char delimiter) throws NumberFormatException, IOException {
    double[] mlDouble = new double[nrows];
    CsvReader cvsReader = new CsvReader(inFilePath.toString());
    cvsReader.setDelimiter(delimiter);
    int i = 0;
    while (cvsReader.readRecord()) {
        String[] rows = cvsReader.getValues();
        for (String col : rows) {
            mlDouble[i] = Double.parseDouble(col);
        }
        i++;
        if (i >= nrows) {
            break;
        }
    }
    return mlDouble;
}
 
Example 4
Source File: UnstructuredStorageReaderUtil.java    From DataLink with Apache License 2.0 6 votes vote down vote up
/**
 * @param inputLine
 *            输入待分隔字符串
 * @param delimiter
 *            字符串分割符
 * @return 分隔符分隔后的字符串数组,出现异常时返回为null 支持转义,即数据中可包含分隔符
 * */
public static String[] splitOneLine(String inputLine, char delimiter) {
	String[] splitedResult = null;
	if (null != inputLine) {
		try {
			CsvReader csvReader = new CsvReader(new StringReader(inputLine));
			csvReader.setDelimiter(delimiter);
			if (csvReader.readRecord()) {
				splitedResult = csvReader.getValues();
			}
		} catch (IOException e) {
			// nothing to do
		}
	}
	return splitedResult;
}
 
Example 5
Source File: CSPARQLAarhusParkingStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CSPARQLAarhusParkingStream(String uri, String txtFile, EventDeclaration ed) throws IOException {
	super(uri);
	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
}
 
Example 6
Source File: CQELSAarhusParkingStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CQELSAarhusParkingStream(ExecContext context, String uri, String txtFile, EventDeclaration ed, Date start,
		Date end) throws IOException {
	super(context, uri);

	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	this.startDate = start;
	this.endDate = end;
}
 
Example 7
Source File: CQELSAarhusParkingStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CQELSAarhusParkingStream(ExecContext context, String uri, String txtFile, EventDeclaration ed)
		throws IOException {
	super(context, uri);
	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
}
 
Example 8
Source File: CQELSAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CQELSAarhusTrafficStream(ExecContext context, String uri, String txtFile, EventDeclaration ed, Date start,
		Date end) throws IOException {
	super(context, uri);
	this.startDate = start;
	this.endDate = end;
	messageCnt = 0;
	byteCnt = 0;
	this.txtFile = txtFile;
	this.ed = ed;
	streamData = new CsvReader(String.valueOf(txtFile));
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
	metaData.readHeaders();
	streamData.readRecord();
	while (metaData.readRecord()) {
		if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
			// p1Street = metaData.get("POINT_1_STREET");
			// p1City = metaData.get("POINT_1_CITY");
			// p1Lat = metaData.get("POINT_1_LAT");
			// p1Lon = metaData.get("POINT_1_LNG");
			// p1Country = metaData.get("POINT_2_COUNTRY");
			// p2Street = metaData.get("POINT_2_STREET");
			// p2City = metaData.get("POINT_2_CITY");
			// p2Lat = metaData.get("POINT_2_LAT");
			// p2Lon = metaData.get("POINT_2_LNG");
			// p2Country = metaData.get("POINT_2_COUNTRY");
			distance = metaData.get("DISTANCE_IN_METERS");
			// timestamp = metaData.get("TIMESTAMP");
			// id = metaData.get("extID");
			metaData.close();
			break;
		}
	}
}
 
Example 9
Source File: CSPARQLAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CSPARQLAarhusTrafficStream(String uri, String txtFile, EventDeclaration ed, Date start, Date end)
		throws IOException {
	super(uri);
	logger.info("IRI: " + this.getIRI().split("#")[1] + ed.getInternalQos());
	this.startDate = start;
	this.endDate = end;
	messageCnt = 0;
	byteCnt = 0;
	this.txtFile = txtFile;
	this.ed = ed;
	streamData = new CsvReader(String.valueOf(txtFile));
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
	metaData.readHeaders();
	streamData.readRecord();
	while (metaData.readRecord()) {
		if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
			// p1Street = metaData.get("POINT_1_STREET");
			// p1City = metaData.get("POINT_1_CITY");
			// p1Lat = metaData.get("POINT_1_LAT");
			// p1Lon = metaData.get("POINT_1_LNG");
			// p1Country = metaData.get("POINT_2_COUNTRY");
			// p2Street = metaData.get("POINT_2_STREET");
			// p2City = metaData.get("POINT_2_CITY");
			// p2Lat = metaData.get("POINT_2_LAT");
			// p2Lon = metaData.get("POINT_2_LNG");
			// p2Country = metaData.get("POINT_2_COUNTRY");
			distance = metaData.get("DISTANCE_IN_METERS");
			if (ed instanceof TrafficReportService)
				((TrafficReportService) ed).setDistance(Integer.parseInt(distance));

			// timestamp = metaData.get("TIMESTAMP");
			// id = metaData.get("extID");
			metaData.close();
			break;
		}
	}
}
 
Example 10
Source File: CQELSAarhusPollutionStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CQELSAarhusPollutionStream(ExecContext context, String uri, String txtFile, EventDeclaration ed)
		throws IOException {
	super(context, uri);
	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
}
 
Example 11
Source File: CSPARQLAarhusPollutionStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CSPARQLAarhusPollutionStream(String uri, String txtFile, EventDeclaration ed, Date start, Date end)
		throws IOException {
	super(uri);

	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	this.startDate = start;
	this.endDate = end;
}
 
Example 12
Source File: CSPARQLAarhusPollutionStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CSPARQLAarhusPollutionStream(String uri, String txtFile, EventDeclaration ed) throws IOException {
	super(uri);
	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
}
 
Example 13
Source File: CSPARQLAarhusParkingStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CSPARQLAarhusParkingStream(String uri, String txtFile, EventDeclaration ed, Date start, Date end)
		throws IOException {
	super(uri);
	logger.info("init");
	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	this.startDate = start;
	this.endDate = end;
}
 
Example 14
Source File: CQELSAarhusWeatherStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CQELSAarhusWeatherStream(ExecContext context, String uri, String txtFile, EventDeclaration ed, Date start,
		Date end) throws IOException {
	super(context, uri);
	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	this.startDate = start;
	this.endDate = end;
}
 
Example 15
Source File: CSPARQLAarhusWeatherStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CSPARQLAarhusWeatherStream(String uri, String txtFile, EventDeclaration ed) throws IOException {
	super(uri);
	streamData = new CsvReader(String.valueOf(txtFile));
	this.ed = ed;
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
}
 
Example 16
Source File: Utils.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public static List readHistoDataFromCsv(Path inFilePath, char delimiter) throws NumberFormatException, IOException {
    ArrayList retList = new ArrayList();

    int numberOfCSVLines = countLines(inFilePath);
    numberOfCSVLines = numberOfCSVLines - 1; //take into account header

    CsvReader cvsReader = new CsvReader(inFilePath.toString());
    cvsReader.setDelimiter(delimiter);
    int i = 0;
    cvsReader.readHeaders();


    String[] headers = cvsReader.getHeaders();
    retList.add(headers);

    double[][] mlDouble = new double[numberOfCSVLines][headers.length];

    while (cvsReader.readRecord()) {
        String[] rows = cvsReader.getValues();
        int j = 0;
        for (String col : rows) {
            if (j > 1) {

                mlDouble[i][j - 2] = (col != null) ? Double.parseDouble(col) : 0.0;
            }
            j++;
        }
        i++;
        if (i >= numberOfCSVLines) {
            break;
        }

    }
    retList.add(mlDouble);
    return retList;
}
 
Example 17
Source File: CSVMatrixReader.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public CSVMatrixReader(InputStream inputStream, char delimiter, String encoding) throws IOException {

        Reader rdr = new UnicodeReader(inputStream, encoding);

        reader = new CsvReader(rdr);
        reader.setDelimiter(delimiter);
        reader.setSkipEmptyRecords(false);
        reader.setTrimWhitespace(true);
        readRecord();
    }
 
Example 18
Source File: FileOperation.java    From Benchmark with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
	// File trafficRawDirectory = new File("streams");
	// File[] trafficRawFiles = trafficRawDirectory.listFiles();
	// for (File tr : trafficRawFiles) {
	// System.out.println("renaming: " + tr.toPath());
	// File newTr;
	// if (tr.getName().contains("traffic")) {
	// newTr = new File("streams" + File.separator + "AarhusT"
	// + tr.getName().substring(1, tr.getName().length()));
	// tr.renameTo(newTr);
	// } else if (tr.getName().contains("pollution")) {
	// newTr = new File("streams" + File.separator + "AarhusP"
	// + tr.getName().substring(1, tr.getName().length()));
	// tr.renameTo(newTr);
	// }
	//
	// // Files.copy(tr.toPath(), newTr.toPath());
	// }
	CsvReader streamData = new CsvReader("dataset/aarhus_parking.csv");
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();

	List<String> streamNames = new ArrayList<String>();
	streamNames.add("NORREPORT");
	streamNames.add("BUSGADEHUSET");
	streamNames.add("BRUUNS");
	streamNames.add("SKOLEBAKKEN");
	streamNames.add("SCANDCENTER");
	streamNames.add("SALLING");
	streamNames.add("MAGASIN");
	streamNames.add("KALKVAERKSVEJ");

	Map<String, CsvWriter> writerMap = new HashMap<String, CsvWriter>();
	for (String s : streamNames)
		try {
			// use FileWriter constructor that specifies open for appending
			String outputFile = "dataset/AarhusParkingData-" + s + ".stream";
			boolean alreadyExists = new File(outputFile).exists();
			CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');

			// if the file didn't already exist then we need to write out the header line
			if (!alreadyExists) {
				csvOutput.write("vehiclecount");
				csvOutput.write("updatetime");
				csvOutput.write("_id");
				csvOutput.write("totalspaces");
				csvOutput.write("garagecode");
				csvOutput.write("streamtime");
				csvOutput.endRecord();
			}
			// }
			writerMap.put(s, csvOutput);
			// csvOutput.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	while (streamData.readRecord()) {
		String code = streamData.get("garagecode");
		writerMap.get(code).write(streamData.get("vehiclecount"));
		writerMap.get(code).write(streamData.get("updatetime"));
		writerMap.get(code).write(streamData.get("_id"));
		writerMap.get(code).write(streamData.get("totalspaces"));
		writerMap.get(code).write(streamData.get("garagecode"));
		writerMap.get(code).write(streamData.get("streamtime"));
		writerMap.get(code).endRecord();
	}
	for (CsvWriter csv : writerMap.values())
		csv.close();
}
 
Example 19
Source File: CQELSAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 4 votes vote down vote up
public CQELSAarhusTrafficStream(ExecContext context, String uri, String txtFile, EventDeclaration ed)
		throws IOException {
	super(context, uri);
	String fileName = "";
	if (this.getURI().split("#").length > 1)
		fileName = this.getURI().split("#")[1];
	else
		fileName = this.getURI();
	// logFile = new File("resultlog/" + fileName + ".csv");
	// fw = new FileWriter(logFile);
	// cw = new CsvWriter(fw, ',');
	// cw.write("time");
	// cw.write("message_cnt");
	// cw.write("byte_cnt");
	// cw.endRecord();
	// cw.flush();
	messageCnt = 0;
	byteCnt = 0;
	this.txtFile = txtFile;
	this.ed = ed;
	// time1 = time.getTime();
	streamData = new CsvReader(String.valueOf(txtFile));
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	// streamData.skipRecord();
	metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
	metaData.readHeaders();
	streamData.readRecord();
	while (metaData.readRecord()) {
		if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
			// p1Street = metaData.get("POINT_1_STREET");
			// p1City = metaData.get("POINT_1_CITY");
			// p1Lat = metaData.get("POINT_1_LAT");
			// p1Lon = metaData.get("POINT_1_LNG");
			// p1Country = metaData.get("POINT_2_COUNTRY");
			// p2Street = metaData.get("POINT_2_STREET");
			// p2City = metaData.get("POINT_2_CITY");
			// p2Lat = metaData.get("POINT_2_LAT");
			// p2Lon = metaData.get("POINT_2_LNG");
			// p2Country = metaData.get("POINT_2_COUNTRY");
			distance = metaData.get("DISTANCE_IN_METERS");
			// timestamp = metaData.get("TIMESTAMP");
			// id = metaData.get("extID");
			// stream(n(RDFFileManager.defaultPrefix + streamData.get("REPORT_ID")),
			// n(RDFFileManager.ctPrefix + "hasETA"), n(data.getEstimatedTime() + ""));
			// System.out.println("metadata: " + metaData.toString());
			metaData.close();
			break;
		}
	}
}
 
Example 20
Source File: CSVMappingGenerator.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public void run() throws IOException {
	CsvReader reader = new CsvReader(new FileInputStream(pathToShapefile), Charset.defaultCharset());
	reader.setDelimiter(separator);
	reader.setSafetySwitch(false);

	reader.readHeaders();
	// Iterate the rows

	Path p = Paths.get(pathToShapefile);
	String tmp = p.getFileName().toString();
	String typeName = tmp.substring(0, tmp.lastIndexOf('.'));
	triplesMaps.put(typeName, "");
	triplesMaps.put(typeName, triplesMaps.get(typeName) + printTriplesMap(typeName));
	triplesMaps.put(typeName, triplesMaps.get(typeName) + printLogicalSource(typeName));
	triplesMaps.put(typeName, triplesMaps.get(typeName) + printSubjectMap(baseURI, typeName));

	boolean hasgeometry = false;
	String typeNameGeo = typeName + "_Geometry";
	WKTReader wktReader = new WKTReader();
	String geometry_identifier = null;
	boolean has_record = reader.readRecord();
	for (String header : reader.getHeaders()) {
		String identifier = header;
		if (identifier.equalsIgnoreCase("the_geom")) {
			geometry_identifier = identifier;
			hasgeometry = true;
			continue;
		}
		if (has_record) {
			try {
				if (wktReader.read(reader.get(identifier)) != null) {
					hasgeometry = true;
					geometry_identifier = identifier;
					continue;
				}
			} catch (ParseException e1) {
				System.err.println(reader.get(identifier));
			}
		}

		String datatype = TranslateDataTypeToXSD("String");
		triplesMaps.put(typeName,
				triplesMaps.get(typeName) + printPredicateObjectMap(identifier, identifier, datatype, typeName));

	}

	if (hasgeometry) {
		triplesMaps
				.put(typeName,
						triplesMaps.get(typeName) + printPredicateObjectMap(true, "hasGeometry",
								baseURI + (baseURI.endsWith("/") ? "" : "/") + typeName
										+ "/Geometry/{GeoTriplesID}",
								null, null, "ogc", null, typeName, true, false));
		triplesMaps.put(typeNameGeo, "");
		triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printTriplesMap(typeNameGeo));
		triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printLogicalSource(typeName));
		triplesMaps.put(typeNameGeo,
				triplesMaps.get(typeNameGeo) + printSubjectMap(baseURI, typeName, "ogc", true));
		triplesMaps.put(typeNameGeo,
				triplesMaps.get(typeNameGeo) + printGEOPredicateObjectMaps(geometry_identifier));
	}
	printmapping();
	printontology();
}