use of org.supercsv.cellprocessor.ift.CellProcessor in project Xponents by OpenSextant.
the class TextUtils method initLOCLanguageData.
/**
* This is Libray of Congress data for language IDs. This is offered as a
* tool to help downstream language ID and enrich metadata when tagging data
* from particular countries.
*
* Reference: http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
*
* @throws java.io.IOException
* if resource file is not found
*/
public static void initLOCLanguageData() throws java.io.IOException {
//
// DATA FILE: http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
java.io.InputStream io = TextUtils.class.getResourceAsStream("/ISO-639-2_utf-8.txt");
java.io.Reader featIO = new InputStreamReader(io, "UTF-8");
CsvListReader langReader = new CsvListReader(featIO, new CsvPreference.Builder('"', '|', "\n").build());
CellProcessor[] cells = { new Optional(), new Optional(), new Optional(), new Optional(), new NotNull() };
List<Object> lang = null;
/*
* ISO3,XX,ISO2,NAME,NAME_FR
*/
while ((lang = langReader.read(cells)) != null) {
//
String names = (String) lang.get(3);
if (isBlank(names)) {
continue;
}
if ("NAME".equals(names)) {
continue;
}
List<String> namelist = TextUtils.string2list(names, ";");
String iso3 = (String) lang.get(0);
if (iso3.startsWith("#")) {
continue;
}
String iso2 = (String) lang.get(2);
Language l = new Language(iso3, iso2, namelist.get(0));
addLanguage(l);
}
langReader.close();
// Popular languages that go by other codes.
// ISO languages as listed by LOC are listed with Bibliographic vs.
// Terminological codes.
// FRE vs. FRA are subtle difference for French, but important if you
// cannot find French by lang ID.
//
// Fully override French and Trad Chinese:
Language fr = new Language("fra", "fr", "French");
addLanguage(fr, true);
Language zhtw = new Language("zh-tw", "zt", "Chinese/Taiwain");
addLanguage(zhtw, true);
// Delicately insert more common names and codes as well as locales
// here.
Language zh = new Language("zho", "zh", "Chinese");
languageMapISO639.put("zho", zh);
Language zhcn = new Language("chi", "zh", "Chinese");
languageMapISO639.put("zh-cn", zhcn);
Language fas = new Language("per", "fa", "Farsi");
languageMapISO639.put("farsi", fas);
// Locales of English -- are still "English"
Language en1 = new Language("eng", "en", "English");
languageMapISO639.put("en-gb", en1);
languageMapISO639.put("en-us", en1);
languageMapISO639.put("en-au", en1);
}
use of org.supercsv.cellprocessor.ift.CellProcessor in project voltdb by VoltDB.
the class Symbols method loadFile.
public void loadFile(String filename) {
// Schema for CSV file
final CellProcessor[] processors = new CellProcessor[] { // Symbol
new UniqueHashCode(), // Name
new NotNull(), // LastSale
new NotNull(), // MarketCap
new NotNull(), // ADR TSO
new NotNull(), // IPOyear
new NotNull(), // Sector
new NotNull(), // Industry
new NotNull(), // Summary Quote
new NotNull(), // blank column
new Optional() };
ICsvMapReader mapReader = null;
try {
mapReader = new CsvMapReader(new FileReader(filename), CsvPreference.STANDARD_PREFERENCE);
// the header columns are used as the keys to the Map
final String[] header = mapReader.getHeader(true);
Map<String, Object> tuple;
int rowsRead = 0;
while ((tuple = mapReader.read(header, processors)) != null) {
Symbol s = new Symbol();
s.symbol = (String) tuple.get("Symbol");
String price = (String) tuple.get("LastSale");
if (price.equals("n/a")) {
price = "20";
}
BigDecimal priceBD = new BigDecimal(price);
s.price = priceBD.multiply(BD10000).intValue();
symbols.add(s);
rowsRead++;
}
System.out.printf("Read %d rows from CSV file at: %s\n", rowsRead, filename);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
} finally {
if (mapReader != null) {
try {
mapReader.close();
} catch (Exception e) {
}
}
}
}
use of org.supercsv.cellprocessor.ift.CellProcessor in project apex-malhar by apache.
the class DelimitedFSLoader method getProcessor.
/**
* Returns array of cellprocessors, one for each field
*/
private CellProcessor[] getProcessor(List<Field> fields) {
CellProcessor[] processor = new CellProcessor[fields.size()];
int fieldCount = 0;
for (Field field : fields) {
processor[fieldCount++] = CellProcessorBuilder.getCellProcessor(field.getType(), field.getConstraints());
}
return processor;
}
use of org.supercsv.cellprocessor.ift.CellProcessor in project apex-malhar by apache.
the class CellProcessorBuilder method getLongCellProcessor.
/**
* Method to get cellprocessor for Long with constraints. These constraints
* are evaluated against the Long field for which this cellprocessor is
* defined.
*
* @param constraints
* map of constraints applicable to Long
* @return CellProcessor
*/
private static CellProcessor getLongCellProcessor(Map<String, Object> constraints) {
Boolean required = constraints.get(DelimitedSchema.REQUIRED) == null ? null : Boolean.parseBoolean((String) constraints.get(DelimitedSchema.REQUIRED));
Long equals = constraints.get(DelimitedSchema.EQUALS) == null ? null : Long.parseLong((String) constraints.get(DelimitedSchema.EQUALS));
Long minValue = constraints.get(DelimitedSchema.MIN_VALUE) == null ? null : Long.parseLong((String) constraints.get(DelimitedSchema.MIN_VALUE));
Long maxValue = constraints.get(DelimitedSchema.MAX_VALUE) == null ? null : Long.parseLong((String) constraints.get(DelimitedSchema.MAX_VALUE));
CellProcessor cellProcessor = null;
if (equals != null) {
cellProcessor = new Equals(equals);
cellProcessor = addParseLong(cellProcessor);
} else if (minValue != null || maxValue != null) {
cellProcessor = addLongMinMax(minValue, maxValue);
} else {
cellProcessor = addParseLong(null);
}
if (required == null || !required) {
cellProcessor = addOptional(cellProcessor);
}
return cellProcessor;
}
use of org.supercsv.cellprocessor.ift.CellProcessor in project apex-malhar by apache.
the class CellProcessorBuilder method getDoubleCellProcessor.
/**
* Method to get cellprocessor for Float/Double with constraints. These
* constraints are evaluated against the Float/Double field for which this
* cellprocessor is defined.
*
* @param constraints
* map of constraints applicable to Float/Double
* @return CellProcessor
*/
private static CellProcessor getDoubleCellProcessor(Map<String, Object> constraints) {
Boolean required = constraints.get(DelimitedSchema.REQUIRED) == null ? null : Boolean.parseBoolean((String) constraints.get(DelimitedSchema.REQUIRED));
Double equals = constraints.get(DelimitedSchema.EQUALS) == null ? null : Double.parseDouble((String) constraints.get(DelimitedSchema.EQUALS));
Double minValue = constraints.get(DelimitedSchema.MIN_VALUE) == null ? null : Double.parseDouble((String) constraints.get(DelimitedSchema.MIN_VALUE));
Double maxValue = constraints.get(DelimitedSchema.MAX_VALUE) == null ? null : Double.parseDouble((String) constraints.get(DelimitedSchema.MAX_VALUE));
CellProcessor cellProcessor = null;
if (equals != null) {
cellProcessor = new Equals(equals);
cellProcessor = addParseDouble(cellProcessor);
} else if (minValue != null || maxValue != null) {
cellProcessor = addDoubleMinMax(minValue, maxValue);
} else {
cellProcessor = addParseDouble(null);
}
if (required == null || !required) {
cellProcessor = addOptional(cellProcessor);
}
return cellProcessor;
}
Aggregations