~vono22/narau/trunk

« back to all changes in this revision

Viewing changes to NarauCupcake/src/org/vono/narau/kanji/Kanji.java

  • Committer: Yvon Tanguy
  • Date: 2012-12-15 23:46:16 UTC
  • Revision ID: vono22@yahoo.fr-20121215234616-doiw8zd0vveshmco
Cukcake edition:
- First port of v0.8 on cupcake to froyo.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 *  Copyright (C) 2012 Yvon TANGUY
3
 
 
4
 
    This program is free software: you can redistribute it and/or modify
5
 
    it under the terms of the GNU General Public License as published by
6
 
    the Free Software Foundation, either version 3 of the License, or
7
 
    (at your option) any later version.
8
 
 
9
 
    This program is distributed in the hope that it will be useful,
10
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
    GNU General Public License for more details.
13
 
 
14
 
    You should have received a copy of the GNU General Public License
15
 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 */
17
 
package org.vono.narau.kanji;
18
 
 
19
 
import java.util.ArrayList;
20
 
import java.util.HashMap;
21
 
import java.util.List;
22
 
 
23
 
import android.os.Parcel;
24
 
import android.os.Parcelable;
25
 
import android.util.SparseArray;
26
 
 
27
 
/**
28
 
 * Informations on a kanji<br/>
29
 
 * Datas from kanjivg & kanjidict.
30
 
 */
31
 
public class Kanji implements Parcelable {
32
 
        private static final SparseArray<Kanji> kanjisArrayCache = new SparseArray<Kanji>(5000);
33
 
 
34
 
        /**
35
 
         * Unicode value of this kanji.
36
 
         */
37
 
        public final int codepoint;
38
 
 
39
 
        /**
40
 
         * The main group.
41
 
         */
42
 
        public Group group;
43
 
 
44
 
        /**
45
 
         * G&lt;num&gt; -- the "grade" of the kanji. At most one per line.
46
 
         * <ul>
47
 
         * <li>G1 to G6 indicates the grade level as specified by the Japanese
48
 
         * Ministry of Education for kanji that are to be taught in elementary
49
 
         * school (1006 Kanji). These are sometimes called the "Kyouiku" (education)
50
 
         * kanji and are part of the set of Jouyou (daily use) kanji;</li>
51
 
         * <li>G8 indicates the remaining Jouyou kanji that are to be taught in
52
 
         * secondary school (additional 1130 Kanji);</li>
53
 
         * <li>G9 and G10 indicate Jinmeiyou ("for use in names") kanji which in
54
 
         * addition to the Jouyou kanji are approved for use in family name
55
 
         * registers and other official documents. G9 (774 kanji, of which 628 are
56
 
         * in KANJIDIC) indicates the kanji is a "regular" name kanji, and G10 (209
57
 
         * kanji of which 128 are in KANJIDIC) indicates the kanji is a variant of a
58
 
         * Jouyou kanji;</li>
59
 
         * </ul>
60
 
         */
61
 
        public Integer grade;
62
 
 
63
 
        /**
64
 
         * F&lt;num&gt; -- the frequency-of-use ranking. At most one per line. The
65
 
         * 2,501 most-used characters have a ranking; those characters that lack
66
 
         * this field are not ranked. The frequency is a number from 1 to 2,501 that
67
 
         * expresses the relative frequency of occurrence of a character in modern
68
 
         * Japanese. The data is based on an analysis of word frequencies in the
69
 
         * Mainichi Shimbun over 4 years by Alexandre Girardi. From this the
70
 
         * relative frequencies have been derived. Note:
71
 
         * <ul>
72
 
         * <li>these frequencies are biassed towards words and kanji used in
73
 
         * newspaper articles,</li>
74
 
         * <li>the relative frequencies for the last few hundred kanji so graded is
75
 
         * quite imprecise.</li>
76
 
         * </ul>
77
 
         * 
78
 
         * (Earlier editions of the KANJIDIC file used a frequency-of-use ranking
79
 
         * from the National Language Research Institute (Tokyo), interpreted and
80
 
         * adapted by Jack Halpern.)
81
 
         */
82
 
        public Integer frequency;
83
 
 
84
 
        /**
85
 
         * J&lt;num&gt; -- the level of the Japanese Language Proficiency Test
86
 
         * (JLPT) in which the kanji occurs. (1-4)
87
 
         */
88
 
        public Integer jlpt;
89
 
 
90
 
        /**
91
 
         * S&lt;num&gt; -- the stroke count. At least one per line. If more than
92
 
         * one, the first is considered the accepted count.
93
 
         */
94
 
        public Integer strokeCount;
95
 
 
96
 
        /**
97
 
         * ja_on - the "on" Japanese reading of the kanji, in katakana. Another
98
 
         * attribute r_status, if present, will indicate with a value of "jy"
99
 
         * whether the reading is approved for a "Jouyou kanji". A further attribute
100
 
         * on_type, if present, will indicate with a value of kan, go, tou or
101
 
         * kan'you the type of on-reading.
102
 
         */
103
 
        public String readingsOn;
104
 
 
105
 
        /**
106
 
         * ja_kun - the "kun" Japanese reading of the kanji, usually in hiragana. <br/>
107
 
         * Where relevant the okurigana is also included separated by a ".".
108
 
         * Readings associated with prefixes and suffixes are marked with a "-". A
109
 
         * second attribute r_status, if present, will indicate with a value of "jy"
110
 
         * whether the reading is approved for a "Jouyou kanji".
111
 
         */
112
 
        public String readingsKun;
113
 
 
114
 
        /**
115
 
         * Meaning map: lang for key, meanings '/' separated.
116
 
         */
117
 
        public HashMap<String, String> meanings;
118
 
 
119
 
        /**
120
 
         * This element contains the index numbers and similar unstructured
121
 
         * information such as page numbers in a number of published dictionaries,
122
 
         * and instructional books on kanji.
123
 
         */
124
 
        public ArrayList<DictRef> dictRef;
125
 
 
126
 
        /**
127
 
         * This kanji radicals
128
 
         */
129
 
        public ArrayList<Integer> radicals;
130
 
 
131
 
        /*
132
 
         * Flags for the KanjiDB, to know what was already loaded. 
133
 
         */
134
 
        public boolean kanjiDBLoadKanji;
135
 
        public boolean kanjiDBLoadMeaning;
136
 
        public boolean kanjiDBLoadSVG;
137
 
        public boolean kanjiDBLoadDictRef;
138
 
        public boolean kanjiDBLoadRadicals;
139
 
 
140
 
        private Kanji(int codepoint) {
141
 
                this.codepoint = codepoint;
142
 
                this.group = null;
143
 
                this.frequency = null;
144
 
                this.grade = null;
145
 
                this.jlpt = null;
146
 
                this.strokeCount = null;
147
 
                this.readingsKun = null;
148
 
                this.readingsOn = null;
149
 
                this.meanings = null;
150
 
                this.dictRef = null;
151
 
                this.radicals = null;
152
 
 
153
 
                this.kanjiDBLoadDictRef = false;
154
 
                this.kanjiDBLoadKanji = false;
155
 
                this.kanjiDBLoadMeaning = false;
156
 
                this.kanjiDBLoadSVG = false;
157
 
                this.kanjiDBLoadRadicals = false;
158
 
        }
159
 
 
160
 
        /**
161
 
         * Get the kanji for the specified codepoint.
162
 
         * 
163
 
         * @param codepoint
164
 
         * @return
165
 
         */
166
 
        public static Kanji getKanji(int codepoint) {
167
 
                Kanji kanji = Kanji.kanjisArrayCache.get(codepoint);
168
 
                if (null == kanji) {
169
 
                        kanji = new Kanji(codepoint);
170
 
                        Kanji.kanjisArrayCache.put(codepoint, kanji);
171
 
                }
172
 
                return kanji;
173
 
        }
174
 
 
175
 
        public static void clearCache() {
176
 
                Kanji.kanjisArrayCache.clear();
177
 
        }
178
 
 
179
 
        public void addReadingsOn(String text) {
180
 
                if (null == this.readingsOn) {
181
 
                        this.readingsOn = text;
182
 
                } else {
183
 
                        this.readingsOn += "/" + text;
184
 
                }
185
 
        }
186
 
 
187
 
        public void addReadingsKun(String text) {
188
 
                if (null == this.readingsKun) {
189
 
                        this.readingsKun = text;
190
 
                } else {
191
 
                        this.readingsKun += "/" + text;
192
 
                }
193
 
        }
194
 
 
195
 
        public void addMeaning(String lang, String value) {
196
 
                if (null == this.meanings) {
197
 
                        this.meanings = new HashMap<String, String>(1);
198
 
                }
199
 
                String oldValue = this.meanings.get(lang);
200
 
                if (null == oldValue) {
201
 
                        this.meanings.put(lang, value);
202
 
                } else {
203
 
                        this.meanings.put(lang, oldValue + "/" + value);
204
 
                }
205
 
        }
206
 
 
207
 
        public int describeContents() {
208
 
                return 0;
209
 
        }
210
 
 
211
 
        public void writeToParcel(Parcel dest, int flags) {
212
 
                dest.writeInt(this.codepoint);
213
 
        }
214
 
 
215
 
        public static final Parcelable.Creator<Kanji> CREATOR = new Parcelable.Creator<Kanji>() {
216
 
                public Kanji createFromParcel(Parcel in) {
217
 
                        final int codepoint = in.readInt();
218
 
                        return Kanji.getKanji(codepoint);
219
 
                }
220
 
 
221
 
                public Kanji[] newArray(int size) {
222
 
                        return new Kanji[size];
223
 
                }
224
 
        };
225
 
 
226
 
        /**
227
 
         * Element of a kanji is a group or a path.
228
 
         * 
229
 
         */
230
 
        public static interface Element {
231
 
        }
232
 
 
233
 
        public static class Group implements Element {
234
 
                public final int id;
235
 
                public Integer element;
236
 
                public String position;
237
 
                public String radical;
238
 
                public Integer original;
239
 
                public String part;
240
 
                public String variant;
241
 
                public boolean partial;
242
 
                public boolean radicalForm;
243
 
                public int number;
244
 
                public boolean tradForm;
245
 
                /**
246
 
                 * TBD as of 20120505
247
 
                 */
248
 
                // public String phon;
249
 
 
250
 
                public List<Element> elements;
251
 
 
252
 
                public Group(int id) {
253
 
                        this.id = id;
254
 
                        this.element = null;
255
 
                        this.position = null;
256
 
                        this.radical = null;
257
 
                        this.original = null;
258
 
                        this.part = null;
259
 
                        this.variant = null;
260
 
                        this.partial = false;
261
 
                        this.radicalForm = false;
262
 
                        this.number = 0;
263
 
                        this.tradForm = false;
264
 
                        // this.phon = null;
265
 
                }
266
 
 
267
 
        }
268
 
 
269
 
        public static class Path implements Element {
270
 
                public final int id;
271
 
                public final String type;
272
 
                public final String draw;
273
 
 
274
 
                public Path(int id, String type, String draw) {
275
 
                        this.type = type;
276
 
                        this.draw = draw;
277
 
                        this.id = id;
278
 
                }
279
 
 
280
 
        }
281
 
 
282
 
        public static class DictRef {
283
 
                public final String name;
284
 
                public final String ref;
285
 
 
286
 
                public DictRef(String name, String ref) {
287
 
                        this.name = name;
288
 
                        this.ref = ref;
289
 
                }
290
 
        }
291
 
 
292
 
}
 
 
b'\\ No newline at end of file'