org.daisy.pipeline.nlp.impl.matchrules.AbbrMatchRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nlp-common Show documentation
Show all versions of nlp-common Show documentation
Common API for NLP functionality and XProc steps
The newest version!
package org.daisy.pipeline.nlp.impl.matchrules;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.daisy.pipeline.nlp.TextCategorizer.Category;
import org.daisy.pipeline.nlp.TextCategorizer.MatchMode;
/**
* Match abbreviations such as "i.e." and "i.e".
*/
public class AbbrMatchRule extends CompactAbbrMatchRule {
public AbbrMatchRule(Category category, int priority, boolean caseSensitive,
MatchMode matchMode, boolean capitalSensitive, Locale locale) {
super(category, priority, caseSensitive, matchMode, capitalSensitive, locale);
}
public void init(Collection rawAbbrs) {
List abbrs = new ArrayList();
for (String rawAbbr : rawAbbrs) {
StringBuilder sb = new StringBuilder();
sb.append(rawAbbr.charAt(0));
for (int n = 1; n < rawAbbr.length(); ++n) {
if (rawAbbr.charAt(n - 1) != '-')
sb.append(".");
sb.append(rawAbbr.charAt(n));
}
String extended = sb.toString();
abbrs.add(rawAbbr);
abbrs.add(extended);
}
super.init(abbrs);
}
}