2021年7月5日月曜日

AWSの用語をssmacroで省略系に変換して文字数を減らす

かなりオレオレなやり方ですが、ご紹介。 VSCodeのssmacroというExtensionが気に入っていて、よく使っています。認定試験の勉強ではドキュメントをコピペしてまとめていましたが、文字数を減らしたかったので省略形に変換していました。

変換の例

例えば、この文では S3 に置き替えます。

この Amazon Simple Storage Service (Amazon S3) のご紹介では、このウェブサービスの要点の詳細について説明します。このセクションを読むことで、本サービスの内容と、ビジネスへの利用方法についてご理解いただけます。

こうなります。

このS3のご紹介では、このウェブサービスの要点の詳細について説明します。このセクションを読むことで、本サービスの内容と、ビジネスへの利用方法についてご理解いただけます。

https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/userguide/Welcome.html


例えば、この文ではKDS、KCLに置き替えます。

You can use Amazon Kinesis Data Streams to collect and process large streams of data records in real time. You can create data-processing applications, known as Kinesis Data Streams applications. A typical Kinesis Data Streams application reads data from a data stream as data records. These applications can use the Kinesis Client Library, and they can run on Amazon EC2 instances. You can send the processed records to dashboards, use them to generate alerts, dynamically change pricing and advertising strategies, or send data to a variety of other AWS services. For information about Kinesis Data Streams features and pricing, see Amazon Kinesis Data Streams.

こうなります。

You can use KDS to collect and process large streams of data records in real time. You can create data-processing applications, known as KDS applications. A typical KDS application reads data from a data stream as data records. These applications can use the KCL, and they can run on EC2s. You can send the processed records to dashboards, use them to generate alerts, dynamically change pricing and advertising strategies, or send data to a variety of other AWS services. For information about KDS features and pricing, see KDS.

https://docs.aws.amazon.com/streams/latest/dev/introduction.html

効果

ものによりますが、10%程度は削れるのではないでしょうか。


ssmacro書き方

書き方は公式か、

こちらの当ブログ記事を見てください。


S3で使っている変換の書き方は、こんな感じにしています。
    {
        "args": {
            "find": "Simple Storage Service( \\(*(Amazon )*(S3)\\)*)*",
            "replace": "S3",
            "all": true,
            "reg": true,
            "flag": "gmi"
        },
        "command": "ssmacro.replace"
    },

Kinesisはこちらで、Firehose, Analytics も判定して短縮形にしています。
    {
        "args": {
            "find": "Kinesis Data (S|F|A)(treams*|irehose|nalytics)",
            "replace": "KD$1",
            "all": true,
            "reg": true,
            "flag": "gmi"
        },
        "command": "ssmacro.replace"
    },

日本語と英語の間は不要なスペースが残りがちなので、消します。
    {
        "args": {
            "find": "([a-z0-9]) ([^\\x00-\\x7F])",
            "replace": "$1$2",
            "all": true,
            "reg": true,
            "flag": "gmi"
        },
        "command": "ssmacro.replace"
    },
    {
        "args": {
            "find": "([^\\x00-\\x7F]) ([a-z0-9])",
            "replace": "$1$2",
            "all": true,
            "reg": true,
            "flag": "gmi"
        },
        "command": "ssmacro.replace"
    },/code>

かかる時間

大きいファイル(20万ワードとか)10数秒かかるときもありますが、そこまで苦にはなりません。

あとはお好みで

数えてみると100以上ルールを作っていました。AWSのサービス名の他にも「畳み込みニューラルネットワーク」→「CNN」とか、いつでも「アベイラビリティーゾーン」→「AZ」とか、「アプリケーション|application」→「app」とか。好みでどんどん設定してくとよいと思います。表記ゆれで全ては判定できなかったりもしますので、あまり完璧を目指さないほうがよいかもしれません。

課題

効率的な正規表現がかけていない気がします。とりあえず苦にならないレベルで動いているので放置中ですが・・・。

0 件のコメント:

コメントを投稿