本文整理汇总了Java中org.apache.commons.csv.CSVFormat.TDF属性的典型用法代码示例。如果您正苦于以下问题:Java CSVFormat.TDF属性的具体用法?Java CSVFormat.TDF怎么用?Java CSVFormat.TDF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.csv.CSVFormat
的用法示例。
在下文中一共展示了CSVFormat.TDF属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DebateHTMLParser
public DebateHTMLParser()
throws IOException
{
urlStances = new HashMap<>();
InputStream inputStream = this.getClass().getClassLoader()
.getResourceAsStream("rfd-controversies/rfd-manual-cleaning-controversies.tsv");
CSVParser parser = new CSVParser(new InputStreamReader(inputStream), CSVFormat.TDF);
for (CSVRecord csvRecord : parser) {
boolean keepRFDDebate = "".equals(csvRecord.get(0));
if (keepRFDDebate) {
String url = csvRecord.get(5);
SortedSet<String> stances = new TreeSet<>();
// yes/no stance?
if ("y".equals(csvRecord.get(3))) {
stances.addAll(Arrays.asList("Yes", "No"));
}
else {
stances.addAll(Arrays.asList(csvRecord.get(3), csvRecord.get(4)));
}
if (stances.size() != 2) {
throw new IllegalStateException(
"Expected 2 stances but got " + stances + "; " + csvRecord.get(1));
}
urlStances.put(url, stances);
}
}
}
示例2: evaluateSpeakerAssignments
@Test
public void evaluateSpeakerAssignments() throws Exception {
JCasIterator iter = SimplePipeline
.iteratePipeline(
CollectionReaderFactory.createReaderDescription(XmiReader.class,
XmiReader.PARAM_SOURCE_LOCATION, "src/test/resources/SpeakerIdentifier/tx4z.0.xmi",
XmiReader.PARAM_LENIENT, true),
createEngineDescription(FigureReferenceAnnotator.class),
createEngineDescription(SpeakerIdentifier.class, SpeakerIdentifier.PARAM_CREATE_SPEAKER_FIGURE,
false),
createEngineDescription(XmiWriter.class, XmiWriter.PARAM_TARGET_LOCATION, "target/doc"))
.iterator();
StringBuilder b = new StringBuilder();
CSVPrinter writer = new CSVPrinter(b, CSVFormat.TDF);
SummaryStatistics types = new SummaryStatistics();
SummaryStatistics tokens = new SummaryStatistics();
while (iter.hasNext()) {
JCas jcas = iter.next();
int s = 0;
int all = 0;
Counter<String> unassigned = new Counter<String>();
for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
if (speaker.getFigure() == null) {
unassigned.add(speaker.getCoveredText());
s++;
}
all++;
}
types.addValue(unassigned.size());
tokens.addValue(s);
writer.printRecord(JCasUtil.selectSingle(jcas, Drama.class).getDocumentId(), s, unassigned.size(), all);
}
writer.printRecord("mean", tokens.getMean(), types.getMean());
writer.printRecord("min", tokens.getMin(), types.getMin());
writer.printRecord("max", tokens.getMax(), types.getMax());
writer.close();
System.out.println(b.toString());
}
示例3: getCsvFormat
/**
* Returns a CSVFormat object given the CSV format as a string.
*
* @param format
* @return
*/
private CSVFormat getCsvFormat(String format) {
CSVFormat csvFormat = null;
switch (format.trim().toLowerCase()) {
case "default":
csvFormat = CSVFormat.DEFAULT;
break;
case "excel":
csvFormat = CSVFormat.EXCEL;
break;
case "informixunload":
case "informix-unload":
case "informix_unload":
csvFormat = CSVFormat.INFORMIX_UNLOAD;
break;
case "informixunloadcsv":
case "informix-unload-csv":
case "informix_unload_csv":
csvFormat = CSVFormat.INFORMIX_UNLOAD_CSV;
break;
case "mysql":
csvFormat = CSVFormat.MYSQL;
break;
case "postgres":
case "postgresql-csv":
case "postgresql_csv":
csvFormat = CSVFormat.POSTGRESQL_CSV;
break;
case "postgresql-text":
case "postgresql_text":
csvFormat = CSVFormat.POSTGRESQL_TEXT;
break;
case "rfc4180":
csvFormat = CSVFormat.RFC4180;
case "tdf":
csvFormat = CSVFormat.TDF;
default:
throw new RuntimeException(String.format("CSV format \"%s\" is not among the supported formats"));
}
return csvFormat;
}
示例4: TSVWriter
public TSVWriter() {
super(CSVFormat.TDF);
}
示例5: loadCSV
public static DataTable loadCSV(String fileName, String formatType, VariableType[] colTypesOverride, String[] colNamesOverride, boolean hasHeaderRow) {
try {
// use apache commons io + csv to load but convert to list of String[]
// byte-order markers are handled if present at start of file.
FileInputStream fis = new FileInputStream(fileName);
final Reader reader = new InputStreamReader(new BOMInputStream(fis), "UTF-8");
CSVFormat format;
if ( formatType==null ) {
format = hasHeaderRow ? CSVFormat.RFC4180.withHeader() : CSVFormat.RFC4180;
}
else {
switch ( formatType.toLowerCase() ) {
case "tsv":
format = hasHeaderRow ? CSVFormat.TDF.withHeader() : CSVFormat.TDF;
break;
case "mysql":
format = hasHeaderRow ? CSVFormat.MYSQL.withHeader() : CSVFormat.MYSQL;
break;
case "excel":
format = hasHeaderRow ? CSVFormat.EXCEL.withHeader() : CSVFormat.EXCEL;
break;
case "rfc4180":
default:
format = hasHeaderRow ? CSVFormat.RFC4180.withHeader() : CSVFormat.RFC4180;
break;
}
}
final CSVParser parser = new CSVParser(reader, format);
List<String[]> rows = new ArrayList<>();
int numHeaderNames = parser.getHeaderMap().size();
try {
for (final CSVRecord record : parser) {
String[] row = new String[record.size()];
for (int j = 0; j<record.size(); j++) {
row[j] = record.get(j);
}
rows.add(row);
}
}
finally {
parser.close();
reader.close();
}
VariableType[] actualTypes = computeColTypes(rows, numHeaderNames);
Set<String> colNameSet = parser.getHeaderMap().keySet();
String[] colNames = colNameSet.toArray(new String[colNameSet.size()]);
if ( colNamesOverride!=null ) {
colNames = colNamesOverride;
}
if ( colTypesOverride!=null ) {
actualTypes = colTypesOverride;
}
return fromStrings(rows, actualTypes, colNames, false);
}
catch (Exception e) {
throw new IllegalArgumentException("Can't open and/or read "+fileName, e);
}
}