本文整理匯總了Java中org.supercsv.io.CsvListReader類的典型用法代碼示例。如果您正苦於以下問題:Java CsvListReader類的具體用法?Java CsvListReader怎麽用?Java CsvListReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CsvListReader類屬於org.supercsv.io包,在下文中一共展示了CsvListReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseMatrix
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
public static Table<String, String, Float> parseMatrix(Reader reader) throws IOException {
Table<String, String, Float> table = HashBasedTable.create();
try (ICsvListReader csvReader = new CsvListReader(reader, CsvPreference.STANDARD_PREFERENCE)) {
List<String> columnHeaders = csvReader.read();
List<String> row;
while ((row = csvReader.read()) != null) {
String rowHeader = row.get(0);
for (int i = 1; i < row.size(); i++) {
String columnHeader = columnHeaders.get(i);
String value = row.get(i);
table.put(rowHeader, columnHeader, value == null ? Float.NaN : Float.parseFloat(value));
}
}
}
return table;
}
示例2: getAggregatedCstStatistic
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
static Statistics getAggregatedCstStatistic(final Collection<File> csv_files, CellProcessor[] processors, Integer column_index, boolean header) throws IOException {
final Statistics statistics = new Statistics();
for (File csv : csv_files) {
final CsvListReader reader = getCsvListReader(csv, header);
try {
List<Object> row;
while ((row = reader.read(processors)) != null) {
statistics.addSample((Number) row.get(column_index));
}
}
finally {
IOUtils.closeQuietly(reader);
}
}
return statistics;
}
示例3: getColumns
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
String[] getColumns(Map<String, String> query) throws IOException, InterruptedException {
Objects.requireNonNull(query, "query is null");
Map<String, String> queryMap = new LinkedHashMap<>();
queryMap.put("headers", "true");
queryMap.put("count", "1");
if (query != null) {
queryMap.putAll(query);
}
try (InputStream is = httpClient.getHttpRequest(new HistoDbUrl(config, "itesla/" + HistoQueryType.data + ".csv", queryMap));
CsvListReader reader = new CsvListReader(new InputStreamReader(is), CsvPreference.STANDARD_PREFERENCE)) {
return reader.getHeader(true);
}
}
示例4: getAllDataType
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private void getAllDataType(CsvListReader listReader)
{
List<String> instances;
try {
instances = listReader.read();
while((instances = listReader.read()) != null)
{
for(int i = 0; i < header.length; i++)
{
if(instances.get(i) != null)
{
String type = new String(determineProcessor(instances.get(i)));
dataType.get(header[i]).get("AllDataTypes").add(type);
dataType.get(header[i]).get("AllowedDataTypes").add(type);
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
log.error( e );
}
}
示例5: stream
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
@Override
public Stream<List<String>> stream() {
try {
final Reader reader = new FileReader(dataFile);
final CsvListReader csvReader = new CsvListReader(reader, CsvPreference.STANDARD_PREFERENCE);
// Generate a stream that reads the CSV file line by line
return Stream.generate(() -> propagate(csvReader::read))
.limit(Files.lines(dataFile.toPath()).count()) // Read to the end
.onClose(() -> { // Close all readers
close(csvReader);
close(reader);
});
} catch (IOException e) {
logger.error("Unable to convert file {}: {}", dataFile.getName(), e.getMessage());
}
return Stream.empty();
}
示例6: testSuperCSV
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
@Test
public void testSuperCSV() throws IOException {
final LhaFile lhaFile = new LhaFile(new File("src/test/resources/", "ken_all.lzh"));
try {
final LhaHeader[] entries = lhaFile.getEntries();
for (final LhaHeader entry : entries) {
final CsvListReader reader = new CsvListReader(new InputStreamReader(lhaFile.getInputStream(entry), "Windows-31J"), CsvPreference.STANDARD_PREFERENCE);
try {
List<String> values;
while ((values = reader.read()) != null) {
continue;
}
} finally {
reader.close();
}
}
} finally {
lhaFile.close();
}
}
示例7: readTermsCsv
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private void readTermsCsv() throws IOException {
BufferedReader r = new BufferedReader(new FileReader(termsFile));
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
List<String> header = csvReader.read();
int col;
if (termCol.matches("[0-9]+")) {
col = Integer.parseInt(termCol);
} else {
col = header.indexOf(termCol);
}
List<String> line;
while ((line = csvReader.read()) != null) {
String term = MemeUtils.normalize(line.get(col));
ms.addTerm(term);
terms.add(term);
}
csvReader.close();
}
示例8: run
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
public void run() throws IOException {
init();
BufferedReader r = new BufferedReader(new FileReader(inputFile), 64*1024);
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
BufferedWriter w = new BufferedWriter(new FileWriter(outputFile), 64*1024);
CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
List<String> line = csvReader.read();
int col;
if (colIndexOrName.matches("[0-9]+")) {
col = Integer.parseInt(colIndexOrName);
} else {
col = line.indexOf(colIndexOrName);
}
line.add(newColName);
csvWriter.write(line);
while ((line = csvReader.read()) != null) {
if (line.get(col).matches(regex)) {
line.add("1");
} else {
line.add("0");
}
csvWriter.write(line);
}
csvReader.close();
csvWriter.close();
}
示例9: readTermsCsv
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private void readTermsCsv() throws IOException {
BufferedReader r = new BufferedReader(new FileReader(termsFile));
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
List<String> header = csvReader.read();
int col;
if (termCol.matches("[0-9]+")) {
col = Integer.parseInt(termCol);
} else {
col = header.indexOf(termCol);
}
List<String> line;
while ((line = csvReader.read()) != null) {
String term = MemeUtils.normalize(line.get(col));
ms[0].addTerm(term);
terms.add(term);
if (termCount >= 0 && terms.size() >= termCount) {
break;
}
}
csvReader.close();
}
示例10: loadTerms
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private void loadTerms() throws IOException {
log("Loading terms from " + termFile + "...");
BufferedReader r = new BufferedReader(new FileReader(termFile));
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
List<String> firstLine = csvReader.read();
int col;
if (colIndexOrName.matches("[0-9]+")) {
col = Integer.parseInt(colIndexOrName);
} else {
col = firstLine.indexOf(colIndexOrName);
}
List<String> l;
while ((l = csvReader.read()) != null) {
terms.put(l.get(col), true);
}
csvReader.close();
log("Number of terms loaded: " + terms.size());
}
示例11: readTermsCsv
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private void readTermsCsv() throws IOException {
BufferedReader r = new BufferedReader(new FileReader(termsFile));
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
List<String> header = csvReader.read();
int col;
if (termCol.matches("[0-9]+")) {
col = Integer.parseInt(termCol);
} else {
col = header.indexOf(termCol);
}
List<String> line;
while ((line = csvReader.read()) != null) {
String term = MemeUtils.normalize(line.get(col));
terms.add(term);
termFreq.put(term, 0);
termCommFreq.put(term, new HashMap<String,Integer>());
if (termCount >= 0 && terms.size() >= termCount) {
break;
}
}
csvReader.close();
}
示例12: readSubjectMap
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private void readSubjectMap() throws IOException {
File subjMapFile = new File(MemeUtils.getPreparedDataDir(), "wos-subjects.csv");
BufferedReader r = new BufferedReader(new FileReader(subjMapFile), 64*1024);
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
csvReader.read(); // ignore header
List<String> line;
while ((line = csvReader.read()) != null) {
String wosCat = line.get(0);
String oecdCat = line.get(5);
byte oecdTop = Byte.parseByte(oecdCat.substring(0, 1));
byte cat = 0;
if ("oecdtop".equals(colorScheme)) {
cat = oecdTop;
} else if ("oecdphys".equals(colorScheme)) {
if (oecdTop == 1 || oecdTop == 4) cat = 3;
if (oecdTop == 2) cat = 6;
if (oecdTop == 3) cat = 1;
if (oecdTop == 5 || oecdTop == 6) cat = 2;
if ("1.3".equals(oecdCat)) cat = 5;
}
subjectMap.put(wosCat, cat);
}
csvReader.close();
}
示例13: readTermsCsv
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private void readTermsCsv() throws IOException {
BufferedReader r = new BufferedReader(new FileReader(termsFile));
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
List<String> header = csvReader.read();
int col;
if (termCol.matches("[0-9]+")) {
col = Integer.parseInt(termCol);
} else {
col = header.indexOf(termCol);
}
List<String> line;
while ((line = csvReader.read()) != null) {
String term = MemeUtils.normalize(line.get(col));
terms.add(term);
if (termCount >= 0 && terms.size() >= termCount) {
break;
}
}
csvReader.close();
}
示例14: readTerms
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private void readTerms() throws IOException {
BufferedReader r = new BufferedReader(new FileReader(inputFile), 64*1024);
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
List<String> line = csvReader.read();
int termCol = getColumnIndex(termColIndexOrName, line);
int weightCol = getColumnIndex(weightColIndexOrName, line);
while ((line = csvReader.read()) != null) {
int weight = 1;
if (weightCol > -1) weight = Integer.parseInt(line.get(weightCol));
String term = line.get(termCol);
if (firstTerms) {
if (duplicatesMap.containsKey(term)) continue;
if (count >= n) break;
count++;
list.add(term);
if (!duplicatesAllowed) {
duplicatesMap.put(term, true);
}
} else {
totalWeights += weight;
map.put(totalWeights, term);
}
}
csvReader.close();
}
示例15: readCompleteWorkAuthors
import org.supercsv.io.CsvListReader; //導入依賴的package包/類
private List<String> readCompleteWorkAuthors(String inputFilename) throws FileNotFoundException, IOException {
CellProcessor[] processors = new CellProcessor[62];
for (int x = 0; x < processors.length; x++) {
processors[x] = new ConvertNullTo("");
}
List<String> result = new ArrayList<>(5000);
try (ICsvListReader listReader = new CsvListReader(new FileReader(
inputFilename), CsvPreference.STANDARD_PREFERENCE)) {
listReader.getHeader(true); //skip titles
List<Object> ergList;
while ((ergList = listReader.read(processors)) != null) {
if ("1".equals(ergList.get(5)) && !ergList.get(17).toString().isEmpty()) {
result.add(ergList.get(17).toString());
}
}
}
return result;
}