add code
This commit is contained in:
parent
6ad19f1a4c
commit
80ff0f62fe
|
@ -1,3 +1,3 @@
|
||||||
# waza-hs
|
# waza-hs
|
||||||
|
|
||||||
library for handling japanese text in haskell
|
wazajisho library for handling japanese text in haskell
|
||||||
|
|
7
examples/Main.hs
Normal file
7
examples/Main.hs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import KanaConv (convertHalfToFull)
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
let input = "おいそこのキミ。あっはいはいはいは~い。"
|
||||||
|
let output = convertHalfToFull input
|
||||||
|
putStrLn output
|
36
src/KanaConv.hs
Normal file
36
src/KanaConv.hs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
-- Copyright © 2024 Hashirama Senju
|
||||||
|
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
|
module KanaConv (convertHalfToFull) where -- Export convertHalfToFull function
|
||||||
|
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
|
-- The Kana mapping for half-width to full-width katakana
|
||||||
|
halfToFullMapping :: Map.Map String String
|
||||||
|
halfToFullMapping = Map.fromList
|
||||||
|
[ ("ア", "ア"), ("イ", "イ"), ("ウ", "ウ"), ("エ", "エ"), ("オ", "オ")
|
||||||
|
, ("カ", "カ"), ("キ", "キ"), ("ク", "ク"), ("ケ", "ケ"), ("コ", "コ")
|
||||||
|
, ("サ", "サ"), ("シ", "シ"), ("ス", "ス"), ("セ", "セ"), ("ソ", "ソ")
|
||||||
|
, ("タ", "タ"), ("チ", "チ"), ("ツ", "ツ"), ("テ", "テ"), ("ト", "ト")
|
||||||
|
, ("ナ", "ナ"), ("ニ", "ニ"), ("ヌ", "ヌ"), ("ネ", "ネ"), ("ノ", "ノ")
|
||||||
|
, ("ハ", "ハ"), ("ヒ", "ヒ"), ("フ", "フ"), ("ヘ", "ヘ"), ("ホ", "ホ")
|
||||||
|
, ("マ", "マ"), ("ミ", "ミ"), ("ム", "ム"), ("メ", "メ"), ("モ", "モ")
|
||||||
|
, ("ᄂ", "ヤ"), ("ᆭ", "ユ"), ("ᄃ", "ヨ"), ("ᄄ", "ラ"), ("ᄅ", "リ")
|
||||||
|
, ("ᆰ", "ル"), ("ᆲ", "レ"), ("ᆴ", "ロ"), ("ワ", "ワ"), ("ヲ", "ヲ")
|
||||||
|
, ("ン", "ン"), ("ァ", "ァ"), ("ィ", "ィ"), ("ゥ", "ゥ"), ("ェ", "ェ")
|
||||||
|
, ("ォ", "ォ"), ("ッ", "ッ"), ("ャ", "ャ"), ("ュ", "ュ"), ("ョ", "ョ")
|
||||||
|
, ("。", "。"), ("、", "、"), ("・", "・"), ("゛", "゙"), ("゜", "゚")
|
||||||
|
, ("「", "「"), ("」", "」"), ("ー", "ー")
|
||||||
|
]
|
||||||
|
|
||||||
|
-- Function to replace half-width characters with full-width characters
|
||||||
|
replaceChar :: Char -> String
|
||||||
|
replaceChar char
|
||||||
|
| Just full <- Map.lookup [char] halfToFullMapping = full
|
||||||
|
| otherwise = [char]
|
||||||
|
|
||||||
|
-- Function to convert the entire string
|
||||||
|
convertHalfToFull :: String -> String
|
||||||
|
convertHalfToFull = concatMap replaceChar
|
Loading…
Reference in a new issue