本文整理汇总了Java中org.supercsv.io.CsvListWriter.write方法的典型用法代码示例。如果您正苦于以下问题:Java CsvListWriter.write方法的具体用法?Java CsvListWriter.write怎么用?Java CsvListWriter.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.supercsv.io.CsvListWriter
的用法示例。
在下文中一共展示了CsvListWriter.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: flushTriples
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
public static InputStream flushTriples(Iterable<KiWiTriple> tripleBacklog) throws IOException {
StringWriter out = new StringWriter();
CsvListWriter writer = new CsvListWriter(out, CsvPreference.STANDARD_PREFERENCE);
// reuse the same array to avoid unnecessary object allocation
Object[] rowArray = new Object[10];
List<Object> row = Arrays.asList(rowArray);
for(KiWiTriple t : tripleBacklog) {
rowArray[0] = t.getId();
rowArray[1] = t.getSubject();
rowArray[2] = t.getPredicate();
rowArray[3] = t.getObject();
rowArray[4] = t.getContext();
rowArray[5] = t.getCreator();
rowArray[6] = t.isInferred();
rowArray[7] = t.isDeleted();
rowArray[8] = t.getCreated();
rowArray[9] = t.getDeletedAt();
writer.write(row, tripleProcessors);
}
writer.close();
return IOUtils.toInputStream(out.toString());
}
示例2: writeTermMap
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
private void writeTermMap() throws IOException {
BufferedWriter w = new BufferedWriter(new FileWriter(outputFile));
CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
for (int rfBin = rfSize-1 ; rfBin >= 0 ; rfBin--) {
List<String> columns = new ArrayList<String>(psSize);
for (int psBin = 0 ; psBin < psSize ; psBin++) {
if (termMap[psBin][rfBin] == null) {
columns.add("");
} else {
columns.add(termMap[psBin][rfBin]);
}
}
csvWriter.write(columns);
}
csvWriter.close();
}
示例3: run
import org.supercsv.io.CsvListWriter; //导入方法依赖的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();
}
示例4: processTerms
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
private void processTerms() throws IOException {
log("Filtering and writing output...");
int n = 0;
Writer w = new BufferedWriter(new FileWriter(outputFile));
CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
csvWriter.write("COUNT", "TERM");
for (String term : ngrams.keySet()) {
int c = ngrams.get(term);
if (c >= t) {
n++;
logProgress(n);
csvWriter.write(c, term);
}
}
csvWriter.close();
log("Number of n-grams after filtering: " + n);
}
示例5: writeCSVFile
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
public static void writeCSVFile(File file, List<List<String>> rows)
throws IOException {
StringWriter stringWriter = new StringWriter();
CsvListWriter csvWriter = new CsvListWriter(stringWriter,
CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
for (List<String> list : rows) {
csvWriter.write(list);
}
csvWriter.close();
PrintWriter printWriter = new PrintWriter(file);
printWriter.println(stringWriter.toString());
stringWriter.close();
printWriter.close();
}
示例6: CreateSparseNumericData
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
@Ignore("This is a test only for convenience")
@Test
public void CreateSparseNumericData() throws IOException
{
FileWriter f = new FileWriter("SparseNumbersOnly.csv");
CsvListWriter ff = new CsvListWriter(f, CsvPreference.STANDARD_PREFERENCE);
final int rowsToProduce = 1000000;
int j = 33;
for(int i = 0; i < rowsToProduce; i++)
{
if(j == 0) j = 2;
ff.write(i, i*j, i/(double)j);
j = i*j % 1843;
}
ff.close();
}
示例7: flushTriples
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
public static void flushTriples(Iterable<KiWiTriple> tripleBacklog, OutputStream out) throws IOException {
CsvListWriter writer = new CsvListWriter(new OutputStreamWriter(out), CsvPreference.STANDARD_PREFERENCE);
// reuse the same array to avoid unnecessary object allocation
Object[] rowArray = new Object[10];
List<Object> row = Arrays.asList(rowArray);
for(KiWiTriple t : tripleBacklog) {
rowArray[0] = t.getId();
rowArray[1] = t.getSubject();
rowArray[2] = t.getPredicate();
rowArray[3] = t.getObject();
rowArray[4] = t.getContext();
rowArray[5] = t.getCreator();
rowArray[6] = t.isInferred();
rowArray[7] = t.isDeleted();
rowArray[8] = t.getCreated();
rowArray[9] = t.getDeletedAt();
writer.write(row, tripleProcessors);
}
writer.close();
}
示例8: writeFile
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
protected Object writeFile(String suggestedFilename, CSVSerializer extractor, Response response) throws Exception {
response.type(MimeTypes.Type.TEXT_PLAIN.name());
response.header("Content-disposition", "attachment; filename="+suggestedFilename);
StringWriter bodyWriter = new StringWriter();
CsvPreference csvPreference = CsvPreference.EXCEL_PREFERENCE;
CsvListWriter csvWriter = new CsvListWriter(bodyWriter, csvPreference);
csvWriter.write("sep=" + Character.toString((char) csvPreference.getDelimiterChar()));
extractor.accept(csvWriter);
csvWriter.flush();
return bodyWriter.toString();
}
示例9: writeSuccessColumn
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
private void writeSuccessColumn() throws IOException {
BufferedReader r = new BufferedReader(new FileReader(outputTempFile));
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
Writer w = new BufferedWriter(new FileWriter(outputFile));
CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
Writer wm = new BufferedWriter(new FileWriter(outputMatrixFile));
CsvListWriter csvMatrixWriter = new CsvListWriter(wm, MemeUtils.getCsvPreference());
// Process header:
List<String> line = csvReader.read();
line.add("CITATIONS-" + citationYears + "Y");
csvWriter.write(line);
line.remove(line.size()-2);
line.remove(0);
csvMatrixWriter.write(line);
while ((line = csvReader.read()) != null) {
String doi = line.get(0);
long date = paperDates.get(doi);
boolean completeRow = false;
if (lastDay >= date + 365*citationYears) {
line.add(paperCitations.get(doi).toString());
completeRow = true;
} else {
line.add("-1");
}
csvWriter.write(line);
if (completeRow) {
line.remove(line.size()-2);
line.remove(0);
csvMatrixWriter.write(line);
}
}
csvWriter.close();
csvMatrixWriter.close();
csvReader.close();
}
示例10: run
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
public void run() throws IOException {
init();
loadTerms();
int t = 0;
log("Extracting terms from input file: " + inputFile);
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
String line;
while ((line = reader.readLine()) != null) {
t++;
logProgress(t);
DataEntry d = new DataEntry(line);
recordNgrams(d);
}
reader.close();
log("Total number of documents: " + t);
calculateMinMax();
log("Writing output...");
t = 0;
File csvFile = new File(MemeUtils.getOutputDataDir(), getOutputFileName() + ".csv");
Writer w = new BufferedWriter(new FileWriter(csvFile));
CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
csvWriter.write("TERM", "MAX-ABS-DIFF", "MAX-REL-DIFF");
for (String term : terms.keySet()) {
logProgress(t);
t++;
double absFreqDiff = freqMax.get(term) - freqMin.get(term);
double relFreqDiff = freqMax.get(term) / freqMin.get(term);
csvWriter.write(term, absFreqDiff, relFreqDiff);
}
csvWriter.close();
log("Finished");
}
示例11: writeOutput
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
private void writeOutput() throws IOException {
log("Writing result to output file...");
if (outputFile == null) {
outputFile = new File(MemeUtils.getOutputDataDir(), getOutputFileName() + ".csv");
}
CsvListWriter csvWriter = new CsvListWriter(new BufferedWriter(new FileWriter(outputFile)), MemeUtils.getCsvPreference());
csvWriter.write("COMM-ID", "TIME-AVG", "MEME1", "FSCORE1", "MEME2", "FSCORE2", "...");
for (String comm : communitySequence) {
List<Object> row = new ArrayList<Object>();
row.add(comm);
row.add(timeSum.get(comm) / commFreq.get(comm));
List<Pair<String,Float>> memes = new ArrayList<Pair<String,Float>>(commTopMemes.get(comm));
Collections.sort(memes, new Comparator<Pair<String,Float>>() {
@Override
public int compare(Pair<String,Float> o1, Pair<String,Float> o2) {
return o2.getRight().compareTo(o1.getRight());
}
});
int n = 0;
for (Pair<String,Float> m : memes) {
n++;
if (n > 3 && m.getRight() < 0.05) break;
row.add(m.getLeft());
row.add(m.getRight());
}
csvWriter.write(row);
}
csvWriter.close();
}
示例12: run
import org.supercsv.io.CsvListWriter; //导入方法依赖的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> header = csvReader.read();
boolean[] textual = new boolean[header.size()];
for (String t : textColums.split(",")) {
if (t.isEmpty()) continue;
if (t.matches("[0-9]+")) {
textual[Integer.parseInt(t)] = true;
} else {
textual[header.indexOf(t)] = true;
}
}
List<String> line;
int c = 0;
while ((line = csvReader.read()) != null) {
c++;
for (int i = 0 ; i < line.size() ; i++) {
if (textual[i]) line.set(i, c + "");
}
csvWriter.write(line);
}
csvReader.close();
csvWriter.close();
}
示例13: run
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
public void run() throws IOException {
init();
BufferedReader r = new BufferedReader(new FileReader(inputFile), 64*1024);
CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
List<String> header = csvReader.read();
int col;
if (colIndexOrName.matches("[0-9]+")) {
col = Integer.parseInt(colIndexOrName);
} else {
col = header.indexOf(colIndexOrName);
}
content.add(header);
List<String> line;
while ((line = csvReader.read()) != null) {
double value = Double.parseDouble(line.get(col));
if (uThreshold != null && value > uThreshold) continue;
if (lThreshold != null && value < lThreshold) continue;
sortList.add(Pair.of(content.size(), value));
content.add(line);
}
csvReader.close();
Collections.sort(sortList, new Comparator<Pair<Integer,Double>>() {
@Override
public int compare(Pair<Integer,Double> o1, Pair<Integer,Double> o2) {
if (reversed) {
return Double.compare(o2.getRight(), o1.getRight());
} else {
return Double.compare(o1.getRight(), o2.getRight());
}
}
});
BufferedWriter w = new BufferedWriter(new FileWriter(outputFile), 64*1024);
CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
csvWriter.write(content.get(0));
for (Pair<Integer,Double> p : sortList) {
csvWriter.write(content.get(p.getLeft()));
}
csvWriter.close();
}
示例14: writeTable
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
private void writeTable() throws IOException {
log("Writing CSV file...");
Writer w = new BufferedWriter(new FileWriter(outputFile));
CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
csvWriter.write("write", "something", "here");
csvWriter.close();
}
示例15: writeTable
import org.supercsv.io.CsvListWriter; //导入方法依赖的package包/类
private void writeTable() throws IOException {
log("Calculating meme scores and writing CSV file...");
Writer w = new BufferedWriter(new FileWriter(outputFile));
CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
csvWriter.write("TERM", "ABSFREQ", "RELFREQ", "MM", "M",
"XM", "X", "STICK-" + delta, "SPARK-" + delta, "PS-" + delta, "MS-" + delta);
int progress = 0;
for (String t : ms.getF().keySet()) {
progress++;
logProgress(progress);
double[] v = ms.calculateMemeScoreValues(t, delta);
csvWriter.write(t, ms.getF(t), ms.getRelF(t), ms.getMM(t), ms.getM(t), ms.getXM(t), ms.getX(t), v[0], v[1], v[2], v[3]);
}
csvWriter.close();
}