1 package net.sf.jhunlang.jmorph.analysis.consumer;
2
3 import java.util.Collection;
4
5 import net.sf.jhunlang.jmorph.DictEntry;
6
7 public class BasicConsumer implements AnalysisConsumer
8 {
9 /***
10 * The parent consumer.
11 */
12 protected AnalysisConsumer parent;
13 /***
14 * The current stemming level
15 */
16 protected int level;
17 /***
18 * The configured depth of analysis
19 */
20 protected int depth;
21
22 protected boolean frozen;
23
24 protected Collection analyses;
25
26 public void setDepth(int depth)
27 {
28 this.depth = depth;
29 }
30
31 public void setLevel(int level)
32 {
33 if (!frozen)
34 {
35 this.level = level;
36 }
37 }
38
39 public void freezeLevel(int level)
40 {
41 setLevel(level);
42 frozen = true;
43 }
44
45 public void thawLevel()
46 {
47 frozen = false;
48 }
49
50 public AnalysisConsumer setParentConsumer(AnalysisConsumer parent)
51 {
52 AnalysisConsumer old = this.parent;
53 this.parent = parent;
54 return old;
55 }
56
57 public void setStems(Collection stems)
58 {
59 this.analyses = stems;
60 }
61
62 public Collection getStems()
63 {
64 return analyses;
65 }
66
67 public boolean done()
68 {
69 return parent == null ?
70 (depth <= level && analyses.size() > 0) : parent.done();
71 }
72
73 /***
74 * Return if stemming should be continued.
75 */
76 public boolean continueStemming(String word, DictEntry entry)
77 {
78 return depth >= level;
79 }
80
81 public boolean ignoreCase()
82 {
83 return false;
84 }
85
86 public boolean hasSuffixFlag(int flag)
87 {
88 return false;
89 }
90
91 public AnalysisConsumer getParent()
92 {
93 return parent;
94 }
95 }