1   package org.daisy.pipeline.nlp.impl.matchrules;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.List;
6   import java.util.Locale;
7   
8   import org.daisy.pipeline.nlp.TextCategorizer.Category;
9   import org.daisy.pipeline.nlp.TextCategorizer.MatchMode;
10  
11  /**
12   * Match abbreviations such as "i.e." and "i.e".
13   */
14  public class AbbrMatchRule extends CompactAbbrMatchRule {
15  
16  	public AbbrMatchRule(Category category, int priority, boolean caseSensitive,
17  	        MatchMode matchMode, boolean capitalSensitive, Locale locale) {
18  		super(category, priority, caseSensitive, matchMode, capitalSensitive, locale);
19  	}
20  
21  	public void init(Collection<String> rawAbbrs) {
22  		List<String> abbrs = new ArrayList<String>();
23  		for (String rawAbbr : rawAbbrs) {
24  			StringBuilder sb = new StringBuilder();
25  			sb.append(rawAbbr.charAt(0));
26  			for (int n = 1; n < rawAbbr.length(); ++n) {
27  				if (rawAbbr.charAt(n - 1) != '-')
28  					sb.append(".");
29  				sb.append(rawAbbr.charAt(n));
30  			}
31  			String extended = sb.toString();
32  			abbrs.add(rawAbbr);
33  			abbrs.add(extended);
34  		}
35  
36  		super.init(abbrs);
37  	}
38  }