0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

超軽量な手動data masking用のjavascriptライブラリ

Last updated at Posted at 2022-06-01

manual-data-maskingは超軽量な手動data masking用のjavascriptライブラリです。

截屏2022-06-02 上午9.37.49.png

Repository link

手動data maskingとは?

手動data maskingはテキストデータ内に存在する個人情報や悪い言葉などの機密情報とセンシティブな情報を手動でラベルを付けたり隠したりする操作です。

例えば、下記のようなユーザーコメントがあります:

くそー、先週買ったばかりの携帯なんだけど、もう壊れてしまった😠、今すぐ返金してくれ!この電話番号080808080で連絡してくれ!

manual-data-maskingを使えば、手動data maskingの作業を簡単に行うことができます:

同時に、ラベル付きのデータセット(data masked)とdata masking後のテキストデータ(text after data masking)も一緒に生成されます:

Data maskedを用いてdata masking関連のAIモデルのtraining data setを構築することができます:

[
  {
    "content": "くそー",
    "category": "Person Name",
    "start": 0, // テキストデータに、機密情報の開始index
    "end": 3 // テキストデータに、機密情報の終了index
  },
  {
    "content": "080808080",
    "category": "Phone Number",
    "start": 49,
    "end": 58
  }
]

Text after data mkasking:

***、先週買ったばかりの携帯なんだけど、もう壊れてしまった😠、今すぐ返金してくれ!この電話番号*********で連絡してくれ!

実際に試してみたら? Online preview

Edit on CodeSandbox

manual-data-maskingの使い方

ES modulesの場合

npm install manual-data-masking
import { create as createManualDataMasking } from "manual-data-masking";

const dataMasked = [
  {
    "content": "Damn it",
    "category": "Person Name",
    "start": 0,
    "end": 7
  }
]

const categories = [
  {
    "value": "Person Name",
    "color": "#b6656c"
  },
  {
    "value": "Swear Word",
    "color": "#577eba"
  },
  {
    "value": "Phone Number",
    "color": "#3e6146"
  }
]

const text = "Damn it, The phone i just bought last week has been broken 😠, \n I need refund right now, Call me on this phone number: 080808080."

const $manualDataMasking = createManualDataMasking({
  container: document.getElementById("demo"),
  text,
  dataMasked,
  categories,
  replaceCharactor: "*",
  dataMaskingCharactor: "X",
  maxHeight: 100
})

$manualDataMasking.on("afterDataMasking", (dataMasked, textAfterDataMasking) => {
  console.log(JSON.stringify(dataMasked));
  console.log(textAfterDataMasking);
})
</script>

Script tagの場合

<script src="https://unpkg.com/manual-data-masking"></script>

<script>
  const dataMasked = [
    {
      content: "Damn it",
      category: "Person Name",
      start: 0,
      end: 7,
    },
  ];

  const categories = [
    {
      value: "Person Name",
      color: "#b6656c",
    },
    {
      value: "Swear Word",
      color: "#577eba",
    },
    {
      value: "Phone Number",
      color: "#3e6146",
    },
  ];

  const text =
    "Damn it, The phone i just bought last week has been broken 😠, \n I need refund right now, Call me on this phone number: 080808080.";

  const $manualDataMasking = manualDataMasking.create({
    container: document.getElementById("demo"),
    text,
    dataMasked,
    categories,
    replaceCharactor: "*",
    dataMaskingCharactor: "X",
    maxHeight: 100,
  });

  $manualDataMasking.on(
    "afterdataMasking",
    (dataMasked, textAfterDataMasking) => {
      console.log(JSON.stringify(dataMasked));
      console.log(textAfterDataMasking);
    }
  );
</script>

Document

パラメータやfunctionについて、詳しくはこちらのdocumentを参照してください:
https://github.com/HC200ok/manual-data-masking#readme

Vue2バージョン

manual-data-maskingには別のVue2のバージョンもあります、こちらのリンクを参照してください:https://github.com/HC200ok/vue2-text-annotation

最後に

manual-data-maskingに関して、何か不具合とか要望とかがありましたら、issueの提出をお願いいたします :pray:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?