Ejemplo n.º 1
0
 protected static void convertAbbreviationsKeys(BaseReader reader, BaseWriter writer)
     throws Exception {
   Set<String> keys = reader.getAbbreviationKeys();
   AbbreviationInfo abbrevInfo = new AbbreviationInfo("", "");
   for (String key : keys) {
     abbrevInfo.setKey(key);
     writer.saveAbbreviationInfo(abbrevInfo);
   }
 }
Ejemplo n.º 2
0
  protected static void convertAbbreviations(
      BaseReader reader, BaseWriter writer, Observer observer, ProgressInfo progress)
      throws Exception {

    Set<String> keys = reader.getAbbreviationKeys();
    if (keys == null) {
      log.info("No abbreviations available");
      return;
    }

    log.info("Number of abbreviations: {}", keys.size());

    // Update progress
    observer.update(progress.setMessage("Sorting Abbreviations"), null);

    ArrayList<String> sortedKeys = new ArrayList<String>(keys.size());
    for (String key : keys) {
      sortedKeys.add(key);
    }

    // Create Collator and sort abbreviations
    Collator collator = createCollator(writer);
    if (collator != null) {
      Collections.sort(sortedKeys, collator);
    } else {
      log.warn("Collator couldn't be created, sorting of Abbreviations is skipped");
    }

    // Update progress
    observer.update(progress.setMessage("Converting Abbreviations"), null);

    for (Iterator<String> iterator = sortedKeys.iterator(); iterator.hasNext(); ) {
      String abbr = iterator.next();
      AbbreviationInfo abbrInfo = reader.getAbbreviationInfo(abbr);
      String definition = abbrInfo.getAbbreviation();
      if (abbr == null
          || definition == null
          || abbr.trim().equals("")
          || definition.trim().equals("")) {
        log.info("Abbreviation {} is excluded", abbrInfo);
        continue;
      }

      abbrInfo.setAbbreviation(abbrInfo.getAbbreviation().trim());
      abbrInfo.setDefinition(abbrInfo.getDefinition().trim());

      writer.saveAbbreviationInfo(reader.getAbbreviationInfo(abbr));
    }

    writer.flush();
  }