Search in sources :

Example 1 with SoundType

use of ai.elimu.model.v2.enums.content.sound.SoundType in project webapp by elimu-ai.

the class CsvContentExtractionHelper method getSoundsFromCsvBackup.

/**
 * For information on how the CSV files were generated, see {@link SoundCsvExportController#handleRequest}.
 */
public static List<Sound> getSoundsFromCsvBackup(File csvFile) {
    logger.info("getSoundsFromCsvBackup");
    List<Sound> sounds = new ArrayList<>();
    Path csvFilePath = Paths.get(csvFile.toURI());
    logger.info("csvFilePath: " + csvFilePath);
    try {
        Reader reader = Files.newBufferedReader(csvFilePath);
        CSVFormat csvFormat = CSVFormat.DEFAULT.withHeader("id", "value_ipa", "value_sampa", "audio_id", "diacritic", "sound_type", "usage_count").withSkipHeaderRecord();
        CSVParser csvParser = new CSVParser(reader, csvFormat);
        for (CSVRecord csvRecord : csvParser) {
            logger.info("csvRecord: " + csvRecord);
            Sound sound = new Sound();
            String valueIpa = csvRecord.get("value_ipa");
            sound.setValueIpa(valueIpa);
            String valueSampa = csvRecord.get("value_sampa");
            sound.setValueSampa(valueSampa);
            boolean diacritic = Boolean.valueOf(csvRecord.get("diacritic"));
            sound.setDiacritic(diacritic);
            if (StringUtils.isNotBlank(csvRecord.get("sound_type"))) {
                SoundType soundType = SoundType.valueOf(csvRecord.get("sound_type"));
                sound.setSoundType(soundType);
            }
            Integer usageCount = Integer.valueOf(csvRecord.get("usage_count"));
            sound.setUsageCount(usageCount);
            sounds.add(sound);
        }
    } catch (IOException ex) {
        logger.error(ex);
    }
    return sounds;
}
Also used : Path(java.nio.file.Path) SoundType(ai.elimu.model.v2.enums.content.sound.SoundType) ArrayList(java.util.ArrayList) Reader(java.io.Reader) Sound(ai.elimu.model.content.Sound) IOException(java.io.IOException) CSVParser(org.apache.commons.csv.CSVParser) CSVFormat(org.apache.commons.csv.CSVFormat) CSVRecord(org.apache.commons.csv.CSVRecord)

Aggregations

Sound (ai.elimu.model.content.Sound)1 SoundType (ai.elimu.model.v2.enums.content.sound.SoundType)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 CSVFormat (org.apache.commons.csv.CSVFormat)1 CSVParser (org.apache.commons.csv.CSVParser)1 CSVRecord (org.apache.commons.csv.CSVRecord)1