List of usage examples for org.apache.lucene.analysis.ja.util CSVUtil parse
public static String[] parse(String line)
From source file:org.codelibs.fess.dict.userdict.UserDictFile.java
License:Apache License
protected void reload(final UserDictUpdater updater) { final List<UserDictItem> itemList = new ArrayList<UserDictItem>(); BufferedReader reader = null; try {/*from ww w .j a va 2 s .c o m*/ reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Constants.UTF_8)); long id = 0; String line = null; while ((line = reader.readLine()) != null) { // Remove comments line = line.replaceAll("#.*$", StringUtil.EMPTY); // Skip empty lines or comment lines if (line.trim().length() == 0) { if (updater != null) { updater.write(line); } continue; } final String[] values = CSVUtil.parse(line); String token = null; String segmentation = null; String reading = null; String pos = null; switch (values.length) { case 4: pos = values[3]; case 3: reading = values[2]; case 2: segmentation = values[1]; case 1: token = values[0]; default: break; } id++; final UserDictItem item = new UserDictItem(id, token, segmentation, reading, pos); if (updater != null) { final UserDictItem newItem = updater.write(item); if (newItem != null) { itemList.add(newItem); } else { id--; } } else { itemList.add(item); } } if (updater != null) { updater.commit(); } userDictItemList = itemList; } catch (final IOException e) { throw new DictionaryException("Failed to parse " + file.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(reader); } }