3時間で「対多」をちょっと中国語っぽくするツール作った

## 我知偽中国語掲示板「対多」

対多、「糞亜不里暦」十日目投稿記事。

↓此
https://zenn.dev/40yd/articles/a73333a16415fa


偽中国語掲示板、非常愉快。
時々本物出没。

https://x.com/shibainu_uraaka/status/1867743186636177771

我、一目判別此本物中国語。
此文章含中国語漢字理由。

我作仮説

**文章含有中国漢字場合、偽中国語本物無条件錯覚？**

## 我製作糞亜不里関連糞亜不里

https://nise-chinese.primitive-ojisan.com/

此糞亜不里、日本漢字変換中国簡体字。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1977360/ed08271d-5235-6952-f505-de4f1631b6d9.png)


## 作業遍歴

我参考此場所。
日本漢字簡体字対応表取得。

https://www.kishugiken.co.jp/technical/%E7%B0%A1%E4%BD%93%E5%AD%97%E5%AF%BE%E7%85%A7%E3%83%AA%E3%82%B9%E3%83%88%EF%BC%88%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A%E9%A0%86%EF%BC%89/

錦蛇便利。白熊猫非常強力。簡単。

```py
import pandas as pd
df_list = pd.read_html("https://www.kishugiken.co.jp/technical/%E7%B0%A1%E4%BD%93%E5%AD%97%E5%AF%BE%E7%85%A7%E3%83%AA%E3%82%B9%E3%83%88%EF%BC%88%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A%E9%A0%86%EF%BC%89/")
pd.concat(df_list)
```


対応表取得後、錦蛇用済。

我書型付台本。
```tsx
import { parse } from "csv-parse/browser/esm";
import { useEffect, useReducer } from "react";

function removeHiraganaKatakanaAlphabet(input: string) {
  const pattern = /[ぁ-んァ-ンa-zA-Z-ー]/g;
  return input.replace(pattern, "");
}

type Action =
  | { type: "SET_INPUT"; payload: string }
  | { type: "TOGGLE_ONLY_KANJI" }
  | { type: "TOGGLE_KANTAI" }
  | { type: "SET_CHAR_MAP"; payload: Map<string, string> };

interface State {
  input: string;
  replacedText: string;
  isOnlyKanji: boolean;
  isKantai: boolean;
  charMap: Map<string, string>;
}

const initialState: State = {
  input: "",
  replacedText: "",
  isOnlyKanji: true,
  isKantai: true,
  charMap: new Map(),
};

function reducer(state: State, action: Action): State {
  switch (action.type) {
    case "SET_INPUT": {
      const replacedText = updateReplacedText(
        action.payload,
        state.isOnlyKanji,
        state.isKantai,
        state.charMap
      );
      return { ...state, input: action.payload, replacedText };
    }
    case "TOGGLE_ONLY_KANJI": {
      const newIsOnlyKanji = !state.isOnlyKanji;
      const replacedText = updateReplacedText(
        state.input,
        newIsOnlyKanji,
        state.isKantai,
        state.charMap
      );
      return { ...state, isOnlyKanji: newIsOnlyKanji, replacedText };
    }
    case "TOGGLE_KANTAI": {
      const newIsKantai = !state.isKantai;
      const replacedText = updateReplacedText(
        state.input,
        state.isOnlyKanji,
        newIsKantai,
        state.charMap
      );
      return { ...state, isKantai: newIsKantai, replacedText };
    }
    case "SET_CHAR_MAP":
      return { ...state, charMap: action.payload };
    default:
      return state;
  }
}

function updateReplacedText(
  inputText: string,
  isOnlyKanji: boolean,
  isKantai: boolean,
  charMap: Map<string, string>
) {
  let replaced = "";
  if (isKantai) {
    for (const t of inputText) {
      replaced += charMap.get(t) ?? t;
    }
  } else {
    replaced = inputText;
  }

  if (isOnlyKanji) {
    replaced = removeHiraganaKatakanaAlphabet(replaced);
  }
  return replaced;
}

export default function App() {
  const [state, dispatch] = useReducer(reducer, initialState);

  useEffect(() => {
    (async () => {
      const res = await fetch("/table.csv");
      const text = await res.text();
      parse(text, { columns: true }, (_err, output) => {
        const map = new Map<string, string>();
        for (const o of output) {
          map.set(o["漢字"], o["簡体字"]);
        }
        dispatch({ type: "SET_CHAR_MAP", payload: map });
      });
    })();
  }, []);

  return (
    <div className="py-4">
      <div className="text-2xl font-bold text-center py-4">
        偽中国語簡易変換機能
      </div>
      <div className="flex flex-col px-8">
        <textarea
          value={state.input}
          onChange={(e) =>
            dispatch({ type: "SET_INPUT", payload: e.target.value })
          }
          placeholder="偽中国語は楽しい也"
        />
        <label>
          <input
            className="mr-2"
            type="checkbox"
            checked={state.isOnlyKanji}
            onChange={() => dispatch({ type: "TOGGLE_ONLY_KANJI" })}
          />
          除去非漢字
        </label>
        <label>
          <input
            className="mr-2"
            type="checkbox"
            checked={state.isKantai}
            onChange={() => dispatch({ type: "TOGGLE_KANTAI" })}
          />
          日本漢字簡体字変換
        </label>
        <div className="text-start py-4">
          <p>{state.replacedText}</p>
        </div>
      </div>
    </div>
  );
}

```

非常適当。平仮名片仮名英数字以外入力可。我罵我罵。
少色気出、使用纏機`(useReducer)`呼出。
我唱Redux不要論。（炎上可能性有発言）

簡単亜不里gradio推奨...？其禁句。