1 package org.daisy.pipeline.nlp.impl;
2
3 import org.daisy.pipeline.nlp.TextCategorizer.CategorizedWord;
4 import org.daisy.pipeline.nlp.TextCategorizer.Category;
5 import org.daisy.pipeline.nlp.TextCategorizer.MatchMode;
6
7
8
9
10
11 public abstract class MatchRule {
12 private final int mPriority;
13 private final Category mCategory;
14 protected final MatchMode mMatchMode;
15 protected final boolean mCaseSensitive;
16
17
18
19
20
21
22
23
24
25
26 public MatchRule(Category category, int priority, boolean caseSensitive,
27 MatchMode matchMode) {
28 mCategory = category;
29 mPriority = priority;
30 mCaseSensitive = caseSensitive;
31 mMatchMode = matchMode;
32 }
33
34 public int getPriority() {
35 return mPriority;
36 }
37
38 public CategorizedWord match(String input, String lowerCaseInput) {
39 String res;
40 if (mCaseSensitive)
41 res = match(input);
42 else
43 res = match(lowerCaseInput);
44 if (res == null)
45 return null;
46 CategorizedWord cw = new CategorizedWord();
47 cw.category = mCategory;
48 cw.word = res;
49 return cw;
50 }
51
52 protected abstract String match(String input);
53
54
55
56
57 public abstract boolean threadsafe();
58 }