コード例 #1
0
ファイル: PruneMinorUPF.java プロジェクト: tibetan-nlp/ttt
  @SuppressWarnings("unchecked")
  @Override
  public void init(NamedList args) {
    Object tagDelimiterParam = args.remove(TAG_DELIMITER_PARAM);
    if (null == tagDelimiterParam || !(tagDelimiterParam instanceof String)) {
      tagDelimiter = TAG_DELIMITER_DEFAULT;
    } else {
      tagDelimiter = (String) tagDelimiterParam;
    }

    Object delimitOutputParam = args.remove(DELIMIT_OUTPUT_PARAM);
    if (null == delimitOutputParam || !(delimitOutputParam instanceof String)) {
      delimitOutput = DELIMIT_OUTPUT_DEFAULT;
    } else {
      delimitOutput = (String) delimitOutputParam;
    }

    Object tagMappingParam = args.remove(TAG_MAPPING_PARAM);
    if (null == tagMappingParam || !(tagMappingParam instanceof String)) {
      // error
    } else {
      String mappingFile = (String) tagMappingParam;

      try {
        FileInputStream fstream = new FileInputStream(mappingFile);
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        while ((strLine = br.readLine()) != null) {
          int n = strLine.indexOf('>');
          if (!(strLine.trim().isEmpty() || n == -1)) {
            remap.put(strLine.substring(0, n).trim(), strLine.substring(n + 1).trim());
          }
        }
        in.close();
      } catch (Exception e) {
        log.error("error", e);
      }
    }

    super.init(args);
  }