{"id":2711,"date":"2013-04-04T12:42:18","date_gmt":"2013-04-04T03:42:18","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2711"},"modified":"2017-02-03T01:19:29","modified_gmt":"2017-02-02T16:19:29","slug":"post-2711","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2711","title":{"rendered":"\u3010D3.js\u3011\u300c\u5168\u30c4\u30a4\u30fc\u30c8\u5c65\u6b74\u300d\u304b\u3089Word cloud\u3092\u4f5c\u3063\u3066\u307f\u305f\u3002"},"content":{"rendered":"<p>\u55dc\u597d\u304c\u30d0\u30ec\u308b\u3002<br \/>\n<a href=\"http:\/\/shimz.me\/example\/d3js\/wordcloud\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/tweetswordcloud.jpg\" alt=\"\u30c4\u30a4\u30fc\u30c8\u30ef\u30fc\u30c9\u30af\u30e9\u30a6\u30c9\" width=\"561\" height=\"566\" class=\"aligncenter size-full wp-image-2714\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/tweetswordcloud.jpg 561w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/tweetswordcloud-150x150.jpg 150w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/tweetswordcloud-149x150.jpg 149w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/tweetswordcloud-100x100.jpg 100w\" sizes=\"auto, (max-width: 561px) 100vw, 561px\" \/><\/a><\/p>\n<p><span class=\"removed_link\" title=\"http:\/\/blog.jp.twitter.com\/2012\/12\/blog-post_20.html\">\u81ea\u5206\u306e\u3059\u3079\u3066\u306e\u30c4\u30a4\u30fc\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f<\/span><br \/>\n<span class=\"removed_link\" title=\"http:\/\/blog.jp.twitter.com\/2013\/03\/blog-post_22.html\">\u65e5\u672c\u306e\u7686\u3055\u3093\u306b\u3082\u300c\u5168\u30c4\u30a4\u30fc\u30c8\u5c65\u6b74\u300d\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f<\/span><\/p>\n<p>\u5168\u30c4\u30a4\u30fc\u30c8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u53ef\u80fd\u306b\u306a\u3063\u3066\u3044\u305f\u306e\u3067\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305ftweets.csv\u3092\u4f7f\u3063\u3066\u30ef\u30fc\u30c9\u30af\u30e9\u30a6\u30c9\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/wordcloud\/index.html\">example<\/a><\/p>\n<h2>\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u4f5c\u6210<\/h2>\n<p>\u904e\u53bb\u306e\u5168\u30c4\u30a4\u30fc\u30c8\u304b\u3089\u56fa\u6709\u540d\u8a5e\u3092\u629c\u304d\u51fa\u3057\u3066\u51fa\u73fe\u56de\u6570\u9806\u306b\u30e9\u30f3\u30ad\u30f3\u30b0\u306b\u3057\u305f\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n2007\u5e74\u304b\u3089\u4f7f\u3063\u3066\u3044\u308b\u308f\u308a\u306b\u3001\u7d2f\u8a08\u30c4\u30a4\u30fc\u30c8\u6570\u304c10,939\u4ef6\u3068\u5c11\u306a\u3044\u306e\u3067\u30c6\u30ad\u30b9\u30c8\u51e6\u7406\u7cfb\u30b3\u30de\u30f3\u30c9\u3068Excel\u3092\u4f7f\u3063\u3066\u884c\u3044\u307e\u3057\u305f\u3002\u30c4\u30a4\u30fc\u30c8\u6570\u304c\u591a\u3044\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u65b9\u6cd5\u3067\u306f\u96e3\u3057\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u307e\u305a\u3001Windows\u3067\u51e6\u7406\u3057\u3084\u3059\u3044\u3088\u3046\u306bS-JIS\u306b\u5909\u63db\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >$ nkf -s tweets.csv &gt; tweets_sjis.csv\n<\/pre>\n<p>\u51fa\u529b\u3057\u305ftweets_sjis.csv\u3092Excel\u3067\u8aad\u307f\u8fbc\u307f\u3001\u30c4\u30a4\u30fc\u30c8(text)\u3060\u3051\u3092\u6b8b\u3057\u3066\u4ed6\u3092\u5168\u3066\u524a\u9664\u3057\u307e\u3059\u3002<br \/>\ntweets_sjis.txt\u3092<a href=\"http:\/\/ja.wikipedia.org\/wiki\/MeCab\">MeCab<\/a>\u306b\u8aad\u307f\u8fbc\u307e\u305b\u5f62\u614b\u7d20\u89e3\u6790\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>MeCab\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u3092\u3002<br \/>\n<a href=\"http:\/\/www.mwsoft.jp\/programming\/munou\/mecab_command.html\">MeCab\u306e\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u5f15\u6570\u4e00\u89a7\u3068\u305d\u306e\u5b9f\u884c\u4f8b<\/a><\/p>\n<pre class=\"lang:sh decode:true \" >$ cat tweets_sjis.txt |mecab &gt; words.txt\n<\/pre>\n<p>\u2193\u3053\u3093\u306a\u611f\u3058\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/twitterWC000001.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"border size-medium wp-image-2712\" alt=\"twitterWC000001\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/twitterWC000001-300x148.jpg\" width=\"300\" height=\"148\" \/><\/a><br \/>\n\u30c7\u30fc\u30bf\u306e\u533a\u5207\u308a\u4f4d\u7f6e\u3068\u30d5\u30a3\u30eb\u30bf\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u56fa\u6709\u540d\u8a5e\u306e\u307f\u53d6\u308a\u51fa\u3057\u3001\u5358\u8a9e\u4ee5\u5916\u3092\u524a\u9664\u3057\u3066\u5225\u30d5\u30a1\u30a4\u30eb(meishi.txt)\u3068\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/twitterWC000002.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/04\/twitterWC000002-300x148.jpg\" alt=\"twitterWC000002\" width=\"300\" height=\"148\" class=\"bordersize-medium wp-image-2713\" \/><\/a><\/p>\n<p>\u4fdd\u5b58\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u30bd\u30fc\u30c8\u3057\u3066\u30e6\u30cb\u30fc\u30af\u3067\u7d5e\u8fbc\u307f\u91cd\u8907\u3092\u30ab\u30a6\u30f3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >sort meishi.txt|uniq -c|sort \/R &gt; ranking.txt\n<\/pre>\n<p>\u3053\u308c\u3067\u5168\u30c4\u30a4\u30fc\u30c8\u304b\u3089\u983b\u51fa\u5358\u8a9e\u306e\u53d6\u51fa\u3057\u304c\u5b8c\u4e86\u3067\u3059\u3002<br \/>\n\u3061\u306a\u307f\u306b\u4e0a\u4f4d10\u4ef6\u306f\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<pre class=\"lang:default decode:true \" >count word\n 457 \u65e5\u672c\n 253 orz\n 176 \u7fa4\u99ac\n 170 \u9ad8\u5d0e\n  97 \u6771\u4eac\n  64 \u30a2\u30e1\u30ea\u30ab\n  63 Google\n  58 iPhone\n  55 \u4e2d\u56fd\n  51 \u524d\u6a4b\n<\/pre>\n<p>\u3069\u3046\u3084\u3089\u65e5\u672c\u304c\u5927\u597d\u304d\u3089\u3057\u3044\u3002\u305d\u3057\u3066\u51f9\u307f\u307e\u304f\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u307e\u305fExcel\u7b49\u3067csv\u306b\u5909\u63db\u3057\u30c7\u30fc\u30bf\u4f5c\u6210\u4f5c\u696d\u306f\u7d42\u4e86\u3067\u3059\u3002<\/p>\n<h2>\u30ef\u30fc\u30c9\u30af\u30e9\u30a6\u30c9\u306e\u8868\u793a<\/h2>\n<p>D3.js\u3068wordclud\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u4f7f\u7528\u3057\u3066\u30ef\u30fc\u30c9\u30af\u30e9\u30a6\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/jasondavies\/d3-cloud\">jasondavies \/ d3-cloud<br \/>\n<\/a><br \/>\n\u5168\u3066\u306e\u51fa\u73fe\u5358\u8a9e\u306b\u5bfe\u3057\u3066\u51e6\u7406\u3092\u3059\u308b\u3068\u8868\u793a\u3055\u308c\u308b\u307e\u3067\u306b\u304b\u306a\u308a\u6642\u9593\u304c\u304b\u304b\u308b\u306e\u30671200\u4ef6\u306b\u7d5e\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" >d3.csv(\u2018ranking.csv\u2019, function(data){\n\tvar h = 800;\n\tvar w = 800;\n\tdata = data.splice(0, 1200); \/\/\u51e6\u7406word\u30921200\u4ef6\u306b\u7d5e\u308b\n\n\tvar random = d3.random.irwinHall(2)\n\n\tvar countMax = d3.max(data, function(d){ return d.count} );\n\tvar sizeScale = d3.scale.linear().domain([0, countMax]).range([10, 100])\n\tvar colorScale = d3.scale.category20();\n\n\tvar words = data.map(function(d) {\n\t\treturn {\n\t\ttext: d.word,\n\t\tsize: sizeScale(d.count) \/\/\u983b\u51fa\u30ab\u30a6\u30f3\u30c8\u3092\u6587\u5b57\u30b5\u30a4\u30ba\u306b\u53cd\u6620\n\t\t};\n\t});\n\n\td3.layout.cloud().size([w, h])\n\t\t.words(words)\n\t\t.rotate(function() { return Math.round(1-random()) *90; }) \/\/\u30e9\u30f3\u30c0\u30e0\u306b\u6587\u5b57\u309290\u5ea6\u56de\u8ee2\n\t\t.font(\"Impact\")\n\t\t.fontSize(function(d) { return d.size; })\n\t\t.on(\"end\", draw) \/\/\u63cf\u753b\u95a2\u6570\u306e\u8aad\u307f\u8fbc\u307f\n\t\t.start();\n\n\t\/\/wordcloud \u63cf\u753b\n\tfunction draw(words) {\n\t\td3.select(\"svg\")\n\t\t.attr({\n\t\t\t\"width\": w,\n\t\t\t\"height\": h\n\t\t})\n\t\t.append(\"g\")\n\t\t.attr(\"transform\", \"translate(150,150)\")\n\t\t.selectAll(\"text\")\n\t\t.data(words)\n\t\t.enter()\n\t\t.append(\"text\")\n\t\t.style({\n\t\t\t\"font-family\": \"Impact\",\n\t\t\t\"font-size\":function(d) { return d.size + \"px\"; },\n\t\t\t\"fill\": function(d, i) { return colorScale(i); }\n\t\t})\n\t\t.attr({\n\t\t\t\"text-anchor\":\"middle\",\n\t\t\t\"transform\": function(d) {\n\t\t\t\treturn \"translate(\" + [d.x, d.y] + \")rotate(\" + d.rotate + \")\";\n\t\t\t}\n\t\t})\n\t\t.text(function(d) { return d.text; });\n\t}\n\n});<\/pre>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/wordcloud\/index.html\">example<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u55dc\u597d\u304c\u30d0\u30ec\u308b\u3002 \u81ea\u5206\u306e\u3059\u3079\u3066\u306e\u30c4\u30a4\u30fc\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2714,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=2711"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2711\/revisions"}],"predecessor-version":[{"id":2950,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2711\/revisions\/2950"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2714"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}