2
* Copyright (C) 2012 Yvon TANGUY
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.
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.
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/>.
17
package org.vono.narau.kanji;
19
import java.util.ArrayList;
20
import java.util.HashMap;
21
import java.util.List;
23
import android.os.Parcel;
24
import android.os.Parcelable;
25
import android.util.SparseArray;
28
* Informations on a kanji<br/>
29
* Datas from kanjivg & kanjidict.
31
public class Kanji implements Parcelable {
32
private static final SparseArray<Kanji> kanjisArrayCache = new SparseArray<Kanji>(5000);
35
* Unicode value of this kanji.
37
public final int codepoint;
45
* G<num> -- the "grade" of the kanji. At most one per line.
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
64
* F<num> -- 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:
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>
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.)
82
public Integer frequency;
85
* J<num> -- the level of the Japanese Language Proficiency Test
86
* (JLPT) in which the kanji occurs. (1-4)
91
* S<num> -- the stroke count. At least one per line. If more than
92
* one, the first is considered the accepted count.
94
public Integer strokeCount;
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.
103
public String readingsOn;
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".
112
public String readingsKun;
115
* Meaning map: lang for key, meanings '/' separated.
117
public HashMap<String, String> meanings;
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.
124
public ArrayList<DictRef> dictRef;
127
* This kanji radicals
129
public ArrayList<Integer> radicals;
132
* Flags for the KanjiDB, to know what was already loaded.
134
public boolean kanjiDBLoadKanji;
135
public boolean kanjiDBLoadMeaning;
136
public boolean kanjiDBLoadSVG;
137
public boolean kanjiDBLoadDictRef;
138
public boolean kanjiDBLoadRadicals;
140
private Kanji(int codepoint) {
141
this.codepoint = codepoint;
143
this.frequency = null;
146
this.strokeCount = null;
147
this.readingsKun = null;
148
this.readingsOn = null;
149
this.meanings = null;
151
this.radicals = null;
153
this.kanjiDBLoadDictRef = false;
154
this.kanjiDBLoadKanji = false;
155
this.kanjiDBLoadMeaning = false;
156
this.kanjiDBLoadSVG = false;
157
this.kanjiDBLoadRadicals = false;
161
* Get the kanji for the specified codepoint.
166
public static Kanji getKanji(int codepoint) {
167
Kanji kanji = Kanji.kanjisArrayCache.get(codepoint);
169
kanji = new Kanji(codepoint);
170
Kanji.kanjisArrayCache.put(codepoint, kanji);
175
public static void clearCache() {
176
Kanji.kanjisArrayCache.clear();
179
public void addReadingsOn(String text) {
180
if (null == this.readingsOn) {
181
this.readingsOn = text;
183
this.readingsOn += "/" + text;
187
public void addReadingsKun(String text) {
188
if (null == this.readingsKun) {
189
this.readingsKun = text;
191
this.readingsKun += "/" + text;
195
public void addMeaning(String lang, String value) {
196
if (null == this.meanings) {
197
this.meanings = new HashMap<String, String>(1);
199
String oldValue = this.meanings.get(lang);
200
if (null == oldValue) {
201
this.meanings.put(lang, value);
203
this.meanings.put(lang, oldValue + "/" + value);
207
public int describeContents() {
211
public void writeToParcel(Parcel dest, int flags) {
212
dest.writeInt(this.codepoint);
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);
221
public Kanji[] newArray(int size) {
222
return new Kanji[size];
227
* Element of a kanji is a group or a path.
230
public static interface Element {
233
public static class Group implements Element {
235
public Integer element;
236
public String position;
237
public String radical;
238
public Integer original;
240
public String variant;
241
public boolean partial;
242
public boolean radicalForm;
244
public boolean tradForm;
248
// public String phon;
250
public List<Element> elements;
252
public Group(int id) {
255
this.position = null;
257
this.original = null;
260
this.partial = false;
261
this.radicalForm = false;
263
this.tradForm = false;
269
public static class Path implements Element {
271
public final String type;
272
public final String draw;
274
public Path(int id, String type, String draw) {
282
public static class DictRef {
283
public final String name;
284
public final String ref;
286
public DictRef(String name, String ref) {
b'\\ No newline at end of file'