1 # -*- coding: utf-8 -*-
3 # Copyright (c) 2009, Paul Goins
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
30 """Helper functions for KANJIDIC and KANJIDIC2 parsers.
32 This module is not intended to be used by itself.
36 def jstring_convert(us
):
37 """Convert's from Jim Breen's -x.xx- notation to 〜x(xx)〜 notation."""
38 if us
[0] == u
'-' or us
[-1] == u
'-':
39 us
= us
.replace(u
'-', u
'〜')
40 parts
= us
.split('.', 1)
41 if len(parts
) == 1: return us
42 return u
"%s(%s)" % tuple(parts
)
44 def kanjidic2_key_to_str(dkey
):
45 """Converts KANJIDIC2 dictionary keys to KANJIDIC2.
47 If unable to find a KANJIDIC2 key, returns the original key.
52 _(u
"New Japanese-English Character Dictionary (Halpern)"),
54 _(u
"Modern Reader's Japanese-English Character Dictionary (Nelson)"),
56 _(u
"The New Nelson Japanese-English Character Dictionary (Haig)"),
57 "sh_kk": _(u
"Kanji and Kana (Spahn/Hadamitzky)"),
58 #"moro": "Morohashi Daikanwajiten" morohashi stuff, ...do later
60 _(u
"A Guide To Remembering Japanese Characters (Henshall)"),
61 "gakken": _(u
"A New Dictionary of Kanji Usage (Gakken)"),
62 "heisig": _(u
"Remembering the Kanji (Heisig)"),
63 "oneill_names": _(u
"Japanese Names (O'Neill)"),
64 "busy_people": _(u
"Japanese For Busy People (AJLT)"),
65 "crowley": _(u
"The Kanji Way to Japanese Language Power (Crowley)"),
66 "jf_cards": _(u
"Japanese Kanji Flashcards (Hodges/Okazaki)"),
67 "kodansha_compact": _(u
"Kodansha Compact Kanji Guide"),
68 "henshall3": _(u
"A Guide To Reading and Writing Japanese (Henshall)"),
69 "kanji_in_context": _(u
"Kanji in Context (Nishiguchi/Kono)"),
70 "halpern_kkld": _(u
"Kodansha Kanji Learners Dictionary (Halpern)"),
71 "oneill_kk": _(u
"Essential Kanji (O'Neill)"),
72 "sakade": _(u
"A Guide To Reading and Writing Japanese (Sakade)"),
73 "tutt_cards": _(u
"Tuttle Kanji Cards (Kask)"),
74 "maniette": _(u
"French version of Heisig (Maniette)")
76 return d
.get(dkey
, dkey
)
78 def qcode_to_desc(qkey
):
82 u
'sh_desc': u
'Spahn/Hadamitzky Kanji Dictionary',
83 u
'four_corner': u
'Four Corner'
85 return d
.get(qkey
, qkey
)