0
3

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 5 years have passed since last update.

こじらせメーターのつくりかた

Posted at

はじめに

twitter でのフォロアーさんとのやりとりで、こじらせ度合いも可視化しないといけないなという話になり、どうせならハッシュタグ__#kojimeter__ つきのツイートを数値化し、集計して可視化するものを Logic Apps で簡単につくることができたので備忘録がてら残しておきます。
(自分宛のMentionっていう条件は、修正時に外しています。)

概要

利用したサービス

  • Cosmos DB (選定理由は後述)
  • Cognitive Services
    • Text Analytics API
  • Logic Apps

Cosmos DB

なぜ Cosmos DB を使っているのかというと、今回の用途からテーブル設計するような内容でもなく、複数のテーブルでリレーションシップを使うものではなく、単に非構造化データをストアしておきたいというだけだったからです。なお、データストアの選択については参考リンクに貼ったデータ ストアの選択条件が参考になります。

今回は、ポータルから作成し、SQLを選びました。特に既存のシステムからの移行ではないしアプリ側(Logic Appsなのでそれすら存在しない)に特定のNoSQLの接続設定があるわけでもないためです。
Collectionも適当に作成しています。
Screen Shot 2018-01-14 at 12.27.47.png

Cognitive Services Text Analytics API

今回、悩んだのが作成時(2018年1月14日)現在ではText Analytics API のセンチメント分析は日本語をサポートしていません。

Supported languages in Text Analytics API

なので、対応言語に一度変換するというステップが入ります。でも、Logic Appsなら簡単にできます。ここは今後無くなるかもしれないステップということになります。
こちらもポータルから作成します。手順は迷うこと無いと思いますがSign up for the Text Analytics APIこちらと同様に作成します。(既に作ってあったので途中の画面は割愛。Logic Apps で使用するので、Show access keysからキーを参照してメモしておきます。)
Screen Shot 2018-01-14 at 12.43.42.png

Logic Apps

ポータルから作成します。こちらのドキュメントが参考になると思います。ロジック アプリでデータを処理するための初めてのワークフローの自動化
今回作った処理は下記の図のようになります。
Screen Shot 2018-01-14 at 12.48.39.png
詳細をひとつひとつ見ていくと

ハッシュタグつきツイートが来たら(トリガー)

Screen Shot 2018-01-14 at 12.50.35.png

ツイート内容を英語に翻訳して

Screen Shot 2018-01-14 at 12.51.49.png

感情を検出して

Screen Shot 2018-01-14 at 12.52.48.png 翻訳したツイート内容から感情を検出します。

Cosmos DB にインサートします。Screen Shot 2018-01-14 at 12.53.53.png

ポイントはインサートする際に、ユニークなidが必要となるのですが、ここは自動生成する関数__guid()__をいれています。

| guid | この関数は、グローバルに一意の文字列 (GUID) を生成します。 たとえば、次の関数は c2ecc88d-88c8-4096-912c-d6f2e2b138ce という GUID を生成できます。 |
|:--|--:|
| guid() |
| |
| パラメーター番号: 1 |
| |
| 名前: Format |
| |
| 説明: 省略可能。 この GUID の値の書式設定方法を示す単一の書式設定指定子です。 指定できる書式設定パラメーターは、"N"、"D"、"B"、"P"、"X" です。 指定しないと、"D" が使われます。 |

最後に完了ツイートを投稿します。

Screen Shot 2018-01-14 at 12.59.58.png

実際にストアされたデータを見るとこんな感じになっています。
Screen Shot 2018-01-14 at 13.02.47.png
作成時に指定した意外に、"-rid","_self","_etag","_attachments","_ts"が付加されていますが、これらはCosmos DB側で付加しているものです。

| Properties of Document |
|:--|:--|
| |
| Property | Description |
| id | This is the unique name that identifies the document, i.e. no two documents can share the same id. The id must not exceed 255 characters. |
| | Any user-defined JSON. |
| _rid | This is a system generated property. The resource ID (_rid) is a unique identifier that is also hierarchical per the resource stack on the resource model. It is used internally for placement and navigation of the document resource. |
| _ts | This is a system generated property. It specifies the last updated timestamp of the resource. The value is a timestamp. |
| _self | This is a system generated property. It is the unique addressable URI for the resource. |
| _etag | This is a system generated property that specifies the resource etag required for optimistic concurrency control. |
| _attachments | This is a system generated property that specifies the addressable path for the attachments resource. |

Properties of Document

結論

ちょっとした作業やロジックを組むのであれば、Logic Appsはとても便利なツールです。コーディングレス、サーバーレスなのでソースコードを書く必要もありません。とても簡単なUIなので、ぜひ一度ご利用くださいませ。

課題

スコアは蓄積したものの、可視化のプロセスをどうしようか悩み中です。Logic Appsでツイートさせるもよし。PowerBIでグラフにするもよし。いいアイデアあれば是非くださいませ。

参考リンク

Azure Cosmos DB のドキュメント
データ ストアの選択条件
Supported languages in Text Analytics API
Sign up for the Text Analytics API
ロジック アプリでデータを処理するための初めてのワークフローの自動化
Azure Logic Apps のワークフロー定義言語スキーマ
Properties of Document

0
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?