Help us understand the problem. What is going on with this article?

Unicode/UTF-8用に漢字を部首ごとにインデックスしてみた

More than 1 year has passed since last update.

ⵙⵓはじめに

ハードコア抽象文學者のkammulticaです.
現在,人工言語を開発しております.中間生成物を上げていきます.

使用言語:Python 3.6.5
最終目的:人工言語の運転
※人工言語自体のコンセプトはブログ,根本のコンセプトは自サイト参照のこと.


ⵖⵓ部首空間の生成に向けた索引付け

CJK統合漢字はUnicodeの19986(4E00)~40943(9FEF)までを占めており,これは部首 (一~龠)の画数の少ない順に並んでいます[参照].が,Unicode(16進数)から索引的にこれらを呼び出すことは不可能です.まずはこれの索引付けをおこないます.

以下の形式で部首のインデックスを構成します.形式はべつに何でも良いのですが,今後の発展性を見据えて,数値配列を辞書に格納しておきます.

辞書型
キー:部首名
値 :当該部首に属する漢字の全10進数値(配列)

なお,pythonは変数名に英字以外の文字を指定することが可能であるため, 部首をそのまま索引名として用いています.

できあがったものがコチラ.(pythonのrangeは(a, b)でab-1を指定する)

# 1画
 = list(range(19968, 20008))
 = list(range(20008, 20022))
 = list(range(20022, 20031))
丿 = list(range(20031, 20057))
 = list(range(20057, 20101)) # "乚"含む。
 = list(range(20101, 20108))

# 2画
 = list(range(20108, 20128))
 = list(range(20128, 20154))
 = list(range(20154, 20799)) # "亻"含む。
 = list(range(20799, 20837))
 = list(range(20837, 20843))
 = list(range(20843, 20866))
 = list(range(20866, 20886))
 = list(range(20886, 20907))
 = list(range(20907, 20960))
 = list(range(20960, 20981)) # "⺇"含む。 
 = list(range(20981, 20992))
 = list(range(20992, 21147)) # "刂"含む。
 = list(range(21147, 21241))
 = list(range(21241, 21269))
 = list(range(21269, 21274))
 = list(range(21274, 21304))
 = list(range(21304, 21313))
 = list(range(21313, 21340))
 = list(range(21340, 21353))
 = list(range(21353, 21378)) #"㔾"含む。
 = list(range(21378, 21430))
 = list(range(21430, 21448))
 = list(range(21448, 21475))

# 3画
 = list(range(21475, 22231)) # kuchi
 = list(range(22231, 22303)) # kunigamae
 = list(range(22303, 22763))
 = list(range(22763, 22786))
 = list(range(22786, 22794))
 = list(range(22794, 22805))
 = list(range(22805, 22823))
 = list(range(22823, 22899))
 = list(range(22899, 23376))
 = list(range(23376, 23424))
 = list(range(23424, 23544))
 = list(range(23544, 23567))
 = list(range(23567, 23586))
 = list(range(23586, 23608))
 = list(range(23608, 23662))
 = list(range(23662, 23665))
 = list(range(23665, 24027))
 = list(range(24027, 24037)) # "川"含む。
 = list(range(24037, 24049))
 = list(range(24049, 24062))
 = list(range(24062, 24178))
 = list(range(24178, 24186))
 = list(range(24186, 24191))
广 = list(range(24191, 24308))
 = list(range(24308, 24318))
 = list(range(24318, 24331))
 = list(range(24331, 24339))
 = list(range(24339, 24400))
 = list(range(24400, 24417))
 = list(range(24417, 24435))
 = list(range(24435, 24515))
 = list(range(24515, 25096))
 = list(range(25096, 25142))
 = list(range(25142, 25163))
 = list(range(25163, 25903)) #"扌"含む。
 = list(range(25903, 25908))
 = list(range(25908, 25991))
 = list(range(25991, 26007))
 = list(range(26007, 26020))
 = list(range(26020, 26041))
 = list(range(26041, 26080))
 = list(range(26080, 26085))
 = list(range(26085, 26352)) # hi
 = list(range(26352, 26376)) # ihaku
 = list(range(26376, 26408))
 = list(range(26408, 27424))
 = list(range(26424, 27490))
 = list(range(27490, 27513))
 = list(range(27513, 27571))
 = list(range(27571, 27595))
 = list(range(27595, 27604))
 = list(range(27604, 27611))
 = list(range(27611, 27663))
 = list(range(27663, 27668))
 = list(range(27668, 27700))

# 4画
 = list(range(27700, 28779)) # "氵"含む。
 = list(range(28779, 29226))
 = list(range(29226, 29238))
 = list(range(29238, 29243))
 = list(range(29243, 29247))
 = list(range(29243, 29255)) #"丬"含む。
 = list(range(29255, 29273))
 = list(range(29273, 29275))
 = list(range(29275, 29356))
 = list(range(29356, 29572))

# 5画
 = list(range(29572, 29577))
 = list(range(29577, 29916)) #"𤣩"含む。
 = list(range(29916, 29926))
 = list(range(29926, 29976))
 = list(range(29976, 29983))
 = list(range(29983, 29992))
 = list(range(29992, 30000))
 = list(range(30000, 30091))
 = list(range(30091, 30098))
 = list(range(30098, 30326))
 = list(range(30326, 30333))
 = list(range(30333, 30382))
 = list(range(30382, 30399))
 = list(range(30339, 30446))
 = list(range(30446, 30683))
 = list(range(30683, 30690))
 = list(range(30690, 30707))
 = list(range(30707, 31034))
 = list(range(31034, 31160))
 = list(range(31160, 31166))
 = list(range(31166, 31348))
 = list(range(31348, 31435))
 = list(range(31435, 31481))

# 6画
 = list(range(31481, 31859))
 = list(range(31859, 31992))
 = list(range(31992, 32566))
 = list(range(32566, 32593))
 = list(range(32593, 32650)) #"罒"含む。
 = list(range(32650, 32701))
 = list(range(32701, 32769))
 = list(range(32769, 32780))
 = list(range(32780, 32786))
 = list(range(32786, 32819))
 = list(range(32819, 32895))
 = list(range(32895, 32905))
 = list(range(32905, 33251))
 = list(range(33251, 33258))
 = list(range(33258, 33267))
 = list(range(33267, 33276))
 = list(range(33276, 33292))
 = list(range(33292, 33307))
 = list(range(33307, 33311))
 = list(range(33311, 33390))
 = list(range(33390, 33394))
 = list(range(33394, 33400))
 = list(range(33400, 34381))
 = list(range(34381, 34411))
 = list(range(34411, 34880))
 = list(range(34880, 34892))
 = list(range(34892, 34915))
 = list(range(34915, 35198))
 = list(range(35198, 35211)) #"西""覀"含む。

# 7画
 = list(range(35211, 35282))
 = list(range(35282, 35328))
 = list(range(35328, 35895))
 = list(range(35895, 35910))
 = list(range(35910, 35925))
 = list(range(35925, 35960))
 = list(range(35960, 35997))
 = list(range(35997, 36196))
 = list(range(36196, 36208))
 = list(range(36208, 36275))
 = list(range(36275, 36523))
 = list(range(36523, 36554))
 = list(range(36554, 36763))
 = list(range(36763, 36784))
 = list(range(36784, 36789))
 = list(range(36789, 37009))
 = list(range(37009, 37193))
 = list(range(37193, 37318))
 = list(range(37318, 37324))
 = list(range(37324, 37329))

# 8画
 = list(range(37329, 38263))
 = list(range(38263, 38272))
 = list(range(38272, 38428))
 = list(range(38428, 38582))
 = list(range(38582, 38585))
 = list(range(38585, 38632))
 = list(range(38632, 38737))
 = list(range(38737, 38750))
 = list(range(38750, 38754))

# 9画
 = list(range(38754, 38761))
 = list(range(38761, 38859))
 = list(range(38859, 38893))
 = list(range(38893, 38899))
 = list(range(38899, 38913))
 = list(range(38913, 39080))
 = list(range(39080, 39131))
 = list(range(39131, 39135))
 = list(range(39135, 39318))
 = list(range(39318, 39321))
 = list(range(39321, 39340))

# 10画
 = list(range(39340, 39592))
 = list(range(39592, 39640))
 = list(range(39640, 39647))
 = list(range(39647, 39717))
 = list(range(39717, 39727))
 = list(range(39727, 39730))
 = list(range(39730, 39740))
 = list(range(39740, 39770))

# 11画
 = list(range(39770, 40165))
 = list(range(40165, 40565))
 = list(range(40565, 40575))
鹿 = list(range(40575, 40613))
 = list(range(40613, 40635))
 = list(range(40635, 40643))
 = list(range(40643, 40653))

# 12画
 = list(range(40653, 40657))
 = list(range(40657, 40697))
 = list(range(40697, 40701))

# 13画
 = list(range(40701, 40718))
 = list(range(40718, 40723))
 = list(range(40723, 40736))
 = list(range(40736, 40763))

# 14画
 = list(range(40763, 40778))
 = list(range(40778, 40786))

# 15画
 = list(range(40786, 40845))

# 16画
 = list(range(40845, 40860))
 = list(range(40860, 40864))

# 16画
 = list(range(40864, 40870))

# その他 (最後尾に詰め込まれた模様)
 = list(range(40870, 40944))

ⵒⵓ蛇足

検証に用いたソースコードを以下に置いておきます.任意の10進数値を指定してfor文をまわすと対応する文字列を吐きます.
(※冗長なのは他プロジェクトのコードを流用したため)

# -----------------------------------ソース--------------------------------------
def unicodation(self, number): # int を 16進数に変換 → utf-16 文字を1つ返す。
    unicodeCharacterHead = ""                                  # \u XX__ 16進数の文字数が足りないときに附加
    unicodeCharacterTail = str(hex(number)).replace("0x", "")  # \u __XX 入力した数(16進数)を文字列として抽出。repは仕様。
    if   len(unicodeCharacterTail) < 4: # \uXXXX 4つで正規。少ない時用
        for shortage in range(4 - len(unicodeCharacterTail)):
            unicodeCharacterHead += str(0)
    elif len(unicodeCharacterTail) > 4: # \uXXXX 多い時用
        unicodeCharacterTail = unicodeCharacterTail[:4]
    else:
        pass

     unicodeCharacter = "\\u" + unicodeCharacterHead + unicodeCharacterTail
     utfCharacter = bytes(unicodeCharacter, 'utf-8').decode('unicode-escape')
     return utfCharacter

# ---------------------------------以下検証用--------------------------------------
x = ""
for kimagure in range(200): # 表示させたい文字数
    x = x + unicodation(kimagure+40864) # 開始位置を+で。
print(x)

思いのほか時間を喰ったので今回の公開に至りました.コピペはご自由にどうぞ.
また,ミスがありましたらコメントにて教えてくださると嬉しいです.

ⵟⵓ参考

kammultica
ハードコア抽象文學者。 目下、人工言語の開発にあたっております。 [Twitter] https://twitter.com/kammulticae
https://spinaltox.org
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした