if (cls == null) {
throw new MissingParameterException("class");
}
ModifyAlgorithm sourceAlgorithm;
ModifyAlgorithm targetAlgorithm = null;
Parser parser = new AlParser(getIn());
List<Alignment> alignmentList = null;
if (cls.equals("split-word")) {
sourceAlgorithm = new WordSplitAlgorithm();
} else if (cls.equals("split-sentence")) {
sourceAlgorithm = new SentenceSplitAlgorithm();
} else if (cls.equals("split-paragraph")) {
sourceAlgorithm = new ParagraphSplitAlgorithm();
} else if (cls.equals("split-srx")) {
String fileName = commandLine.getOptionValue('f');
if (fileName == null) {
throw new MissingParameterException("file");
}
String languages = commandLine.getOptionValue('l');
if (languages == null) {
throw new MissingParameterException("languages");
}
String[] languageArray = languages.split(",");
if (languageArray.length != 2) {
throw new ParameterFormatException("languages");
}
Reader reader = getReader(getFileInputStream(fileName));
sourceAlgorithm = new SrxSplitAlgorithm(reader, languageArray[0]);
reader = getReader(getFileInputStream(fileName));
targetAlgorithm = new SrxSplitAlgorithm(reader, languageArray[1]);
} else if (cls.equals("merge")) {
String separator = commandLine.getOptionValue('s');
if (separator == null) {
sourceAlgorithm = new SeparatorMergeAlgorithm();
} else {
separator = separator.replaceAll("\\\\t", "\t");
separator = separator.replaceAll("\\\\n", "\n");
sourceAlgorithm = new SeparatorMergeAlgorithm(separator);
}
} else if (cls.equals("trim")) {
sourceAlgorithm = new TrimCleanAlgorithm();
} else if (cls.equals("lowercase")) {
sourceAlgorithm = new LowercaseCleanAlgorithm();
} else if (cls.equals("filter-non-words")) {
sourceAlgorithm = new FilterNonWordsCleanAlgorithm();
} else if (cls.equals("unify-rare-words")) {
alignmentList = parser.parse();
Pair<ModifyAlgorithm, ModifyAlgorithm> algorithmPair =
createUnifyRareWordsAlgorithms(commandLine, alignmentList);
sourceAlgorithm = algorithmPair.first;
targetAlgorithm = algorithmPair.second;
} else {
throw new UnknownParameterException("class");
}
String part = commandLine.getOptionValue('p');
if (part == null) {
part = "both";
}
if (part.equals("both")) {
if (targetAlgorithm == null) {
targetAlgorithm = sourceAlgorithm;
}
} else if (part.equals("source")) {
targetAlgorithm = new NullModifyAlgorithm();
} else if (part.equals("target")) {
sourceAlgorithm = new NullModifyAlgorithm();
} else {
throw new UnknownParameterException("part");
}
Formatter formatter = new AlFormatter(getOut());
Filter filter = new Modifier(sourceAlgorithm, targetAlgorithm);
filter = FilterDecorators.decorate(filter);
if (alignmentList == null) {
alignmentList = parser.parse();
}
alignmentList = filter.apply(alignmentList);
formatter.format(alignmentList);
}