1 package net.sf.jhunlang.jmorph.sword;
2
3 import net.sf.jhunlang.jmorph.AffixEntry;
4 import net.sf.jhunlang.jmorph.AffixFlags;
5 import net.sf.jhunlang.jmorph.DictEntry;
6 import net.sf.jhunlang.jmorph.PrefixEntry;
7
8 /***
9 * SwordEntry instances represent the dictionary definitions of
10 * szoszablya root words.
11 */
12 public class SwordEntry extends DictEntry
13 {
14 /***
15 * The deriver of this word if it is derived.
16 */
17 protected AffixEntry deriver;
18
19 protected SwordEntry(String word)
20 {
21 super(word);
22 }
23
24 /***
25 * Create a SwodEntry instance for <code>word</code> with flags
26 * specified in <code>flagCharacters</code>.
27 * @param word the word
28 * @param flagCharacters the affix flag characters
29 * @exception IllegalArgumentException if the word is null
30 */
31 public SwordEntry(String word, char[] flagCharacters)
32 {
33 super(word, flagCharacters);
34 }
35
36 /***
37 * Create a SwodEntry instance for <code>word</code> with flags
38 * specified in <code>flagCharacters</code> with <code>inflexion</code>.
39 * @param word the word
40 * @param flagCharacters the affix flag characters
41 * @param inflexion the inflexion of the word
42 * @exception IllegalArgumentException if the word is null
43 */
44 public SwordEntry(String word, char[] flagCharacters,
45 SwordEntryExtension inflexion, DictEntry root)
46 {
47 this(word, flagCharacters, inflexion);
48 this.root = root;
49 }
50
51 /***
52 * Create a SwodEntry instance for <code>word</code> with flags
53 * specified in <code>flagCharacters</code> with <code>inflexion</code>.
54 * @param word the word
55 * @param flagCharacters the affix flag characters
56 * @param inflexion the inflexion of the word
57 * @exception IllegalArgumentException if the word is null
58 */
59 public SwordEntry(
60 String word, char[] flagCharacters, SwordEntryExtension inflexion)
61 {
62 this(word, flagCharacters);
63 this.inflexion = inflexion;
64 }
65
66 /***
67 * Create a SwodEntry representing the derivation of <code>root</code> by
68 * <code>deriver</code.
69 * @param root the derivation root
70 * @param deriver the deriver
71 * @param add if flags of <code>root</code> are to be added to the derivation
72 * @exception IllegalArgumentException if the word is null
73 */
74 public SwordEntry(DictEntry root, AffixEntry deriver, boolean add)
75 {
76 super(root.inflex(deriver), root,
77 add ? deriver.getFlags().add(root.getFlags()) : deriver.getFlags());
78
79 this.deriver = deriver;
80 if (add)
81 {
82 flags = flags.remove((char)deriver.getFlag());
83 }
84
85 SwordExtension ext = (SwordExtension)deriver.getExtension();
86 SwordEntryExtension swInflexion = new SwordEntryExtension(ext);
87
88 inflexion = swInflexion;
89
90 if (swInflexion.getPOSName() == POSName.empty)
91 {
92 if (root instanceof SwordEntry)
93 {
94 swInflexion.setPOSName(((SwordEntry)root).getPOSName());
95 }
96 }
97 }
98
99 public boolean hasFlag(AffixEntry entry)
100 {
101 if (hasFlag(entry.getFlag()))
102 {
103 return true;
104 }
105 else if (deriver == null)
106 {
107 return false;
108 }
109
110
111 else if (!entry.getExtension().isDerivator() &&
112 root.getPOS() == getPOS() && root.getCaseEnding() == getCaseEnding())
113 {
114 return root.hasFlag(entry);
115 }
116
117
118
119
120 else if ((entry instanceof PrefixEntry) ^ (deriver instanceof PrefixEntry))
121 {
122 return root.hasFlag(entry);
123 }
124 else
125 {
126 return false;
127 }
128 }
129
130 public AffixFlags getAccumulatedFlags()
131 {
132 if (deriver == null)
133 {
134 return super.getAccumulatedFlags();
135 }
136 else if (root.getPOS() == getPOS() &&
137 root.getCaseEnding() == getCaseEnding())
138 {
139 return flags.add(root.getAccumulatedFlags()).add(deriver.getFlags());
140 }
141 else
142 {
143 return super.getAccumulatedFlags();
144 }
145 }
146
147 /***
148 * Tells if this entry represents a derived word.
149 * @return if this entry represents a derived word.
150 */
151 public boolean derived()
152 {
153 return deriver != null || (inflexion != null && inflexion.isDerivator());
154 }
155
156 /***
157 * Tells if this entry represents a dictionary word.
158 * @return if this entry represents a dictionary word.
159 */
160 public boolean dictionaryWord()
161 {
162 return deriver == null;
163 }
164
165 public POSName getPOSName()
166 {
167 return inflexion == null ?
168 null : ((SwordEntryExtension)inflexion).getPOSName();
169 }
170
171 public String getCaseEnding()
172 {
173 if (deriver != null)
174 {
175 return (deriver instanceof PrefixEntry) ?
176 root.getCaseEnding() : deriver.getExtension().getCase();
177 }
178 else
179 {
180 return inflexion != null ? inflexion.getCase() : "";
181 }
182 }
183
184 /***
185 * Return the internal <code>String</code> representation of the content
186 * of this instance
187 * @return the internal <code>String</code> representation
188 */
189 public String longContentString()
190 {
191 if (inflexion != null)
192 {
193 return super.longContentString() + inflexion;
194 }
195 else
196 {
197 return super.longContentString();
198 }
199 }
200
201 /***
202 * Return the internal <code>String</code> representation of the content
203 * of this instance
204 * @return the internal <code>String</code> representation
205 */
206 public String contentString()
207 {
208 if (inflexion != null)
209 {
210 return super.contentString() + inflexion;
211 }
212 else
213 {
214 return super.contentString();
215 }
216 }
217
218 protected String shortClassName()
219 {
220 return deriver == null ? "Sw" : "Dw";
221 }
222 }