diff --git a/README.md b/README.md index cf37718..27363f2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # waza-hs -library for handling japanese text in haskell \ No newline at end of file +wazajisho library for handling japanese text in haskell diff --git a/examples/Main.hs b/examples/Main.hs new file mode 100644 index 0000000..7146c80 --- /dev/null +++ b/examples/Main.hs @@ -0,0 +1,7 @@ +import KanaConv (convertHalfToFull) + +main :: IO () +main = do + let input = "おいそこのキミ。あっはいはいはいは~い。" + let output = convertHalfToFull input + putStrLn output diff --git a/src/KanaConv.hs b/src/KanaConv.hs new file mode 100644 index 0000000..4cd1962 --- /dev/null +++ b/src/KanaConv.hs @@ -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