| Copyright | (c) Colin Woodbury 2015 - 2018 |
|---|---|
| License | GPL3 |
| Maintainer | Colin Woodbury <colingw@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Kanji
Description
A library for analysing the density of Kanji in given texts, according to their Level classification, as defined by the Japan Kanji Aptitude Testing Foundation (日本漢字能力検定協会).
Synopsis
- data Kanji
- kanji :: Char -> Maybe Kanji
- _kanji :: Kanji -> Char
- allKanji :: Map Level (Set Kanji)
- isKanji :: Char -> Bool
- isHiragana :: Char -> Bool
- isKatakana :: Char -> Bool
- data CharCat
- = Hanzi
- | Hiragana
- | Katakana
- | Numeral
- | RomanLetter
- | Punctuation
- | Other
- category :: Char -> CharCat
- data Level
- level :: Kanji -> Level
- percentSpread :: [Kanji] -> Map Kanji Float
- levelDist :: [Kanji] -> Map Level Float
- uniques :: [Kanji] -> Map Level (Set Kanji)
- densities :: Text -> Map CharCat Float
- elementaryDen :: Map Level Float -> Float
- middleDen :: Map Level Float -> Float
- highDen :: Map Level Float -> Float
Kanji
A single symbol of Kanji. Japanese Kanji were borrowed from China over several waves during the last 1,500 years. Japan names 2,136 of these as their standard set, with rarer characters being the domain of academia and esoteric writers.
Japanese has several Japan-only Kanji, including:
- 畑 (a type of rice field)
- 峠 (a narrow mountain pass)
- 働 (to do physical labour)
isHiragana :: Char -> Bool #
あ to ん.
isKatakana :: Char -> Bool #
ア to ン.
Character Categories
General categories for characters, at least as is useful for thinking about Japanese.
Japanese "full-width" numbers and letters will be counted as Numeral
and RomanLetter respectively, alongside their usual ASCII forms.
Constructors
| Hanzi | |
| Hiragana | |
| Katakana | |
| Numeral | |
| RomanLetter | |
| Punctuation | |
| Other |
Instances
| Eq CharCat # | |
| Ord CharCat # | |
| Show CharCat # | |
| Generic CharCat # | |
| Hashable CharCat # | |
Defined in Data.Kanji.Types | |
| ToJSON CharCat # | |
Defined in Data.Kanji.Types | |
| ToJSONKey CharCat # | |
Defined in Data.Kanji.Types | |
| FromJSON CharCat # | |
| NFData CharCat # | |
Defined in Data.Kanji.Types | |
| type Rep CharCat # | |
Defined in Data.Kanji.Types type Rep CharCat = D1 (MetaData "CharCat" "Data.Kanji.Types" "kanji-3.4.0-DVGCwVO8stlDIxqk0jYmH5" False) ((C1 (MetaCons "Hanzi" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "Hiragana" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Katakana" PrefixI False) (U1 :: * -> *))) :+: ((C1 (MetaCons "Numeral" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "RomanLetter" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "Punctuation" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Other" PrefixI False) (U1 :: * -> *)))) | |
Levels
A Level or Kyuu (級) of Japanese Kanji ranking. There are 12 of these, from 10 to 1, including intermediate levels between 3 and 2, and 2 and 1.
Japanese students will typically have Level-5 ability by the time they finish elementary school. Level-5 accounts for 1,006 characters.
By the end of middle school, they would have covered up to Level-3 (1607 Kanji) in their Japanese class curriculum.
While Level-2 (2,136 Kanji) is considered "standard adult" ability, many adults could not pass the Level-2, or even the Level-Pre2 (1940 Kanji) exam without considerable study.
Level data for Kanji above Level-2 is currently not provided by this library.
Instances
Analysis
percentSpread :: [Kanji] -> Map Kanji Float #
The distribution of each Kanji in a set of them.
The distribution values must sum to 1.
levelDist :: [Kanji] -> Map Level Float #
How much of each Level is represented by a group of Kanji?
The distribution values will sum to 1.
Densities
densities :: Text -> Map CharCat Float #
Percentage of appearance of each CharCat in the source text.
The percentages will sum to 1.0.
elementaryDen :: Map Level Float -> Float #
How much of the Kanji found are learnt in elementary school in Japan?
elementaryDen . levelDist :: [Kanji] -> Float