1.ライブラリの設置
今回使ったファイルは
d3.layout.cloud.js
word-cloud.js
d3.v3.min.js
です。app/webroot/jsに配置します。またはURL指定です。
ダウンロードは
https://github.com/shprink/d3js-wordcloud
https://github.com/jasondavies/d3-cloud/tree/master/build
からしました。
2.形態素解析した結果を取り込みます。
今回は View/graph.ctpに書きました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://d3js.org/d3.v3.min.js"></script> | |
<?php echo $this->Html->script('d3.layout.cloud.js');?> | |
<script>var tags = [ | |
<?php for($index = 0; $index < count($weight); $index++){ ?> | |
{"key": "<?php echo $weight[$index][0];?>", "value": <?php echo $weight[$index][1];?>}, | |
<?php }?> | |
] | |
</script> | |
<div id="vis"></div> | |
<?php echo $this->Html->script('word-cloud.js');?> |
オリンピックのtweet結果を形態素分析して、WordCloudで表示するとそれなりでした。
0 件のコメント:
コメントを投稿