Exemplo n.º 1
0
  public static UserDictionary open(Reader reader) throws IOException {

    BufferedReader br = new BufferedReader(reader);
    String line = null;
    List<String[]> featureEntries = new ArrayList<>();

    // text, segmentation, readings, POS
    while ((line = br.readLine()) != null) {
      // Remove comments
      line = line.replaceAll("#.*$", "");

      // Skip empty lines or comment lines
      if (line.trim().length() == 0) {
        continue;
      }
      String[] values = CSVUtil.parse(line);
      featureEntries.add(values);
    }

    if (featureEntries.isEmpty()) {
      return null;
    } else {
      return new UserDictionary(featureEntries);
    }
  }
Exemplo n.º 2
0
 private String getFeature(int wordId, int... fields) {
   String[] allFeatures = getAllFeaturesArray(wordId);
   if (allFeatures == null) {
     return null;
   }
   StringBuilder sb = new StringBuilder();
   if (fields.length == 0) { // All features
     for (String feature : allFeatures) {
       sb.append(CSVUtil.quoteEscape(feature)).append(",");
     }
   } else if (fields.length == 1) { // One feature doesn't need to escape value
     sb.append(allFeatures[fields[0]]).append(",");
   } else {
     for (int field : fields) {
       sb.append(CSVUtil.quoteEscape(allFeatures[field])).append(",");
     }
   }
   return sb.deleteCharAt(sb.length() - 1).toString();
 }