{"id":2783,"date":"2011-05-15T01:43:22","date_gmt":"2011-05-14T16:43:22","guid":{"rendered":"http:\/\/blog.tksk.net\/?p=2783"},"modified":"2011-05-15T13:39:07","modified_gmt":"2011-05-15T04:39:07","slug":"wordcount-scala","status":"publish","type":"post","link":"https:\/\/blog.tksk.net\/?p=2783","title":{"rendered":"WordCount.scala"},"content":{"rendered":"<p>stdin \u304b\u3089\u306e\u5165\u529b\u306b\u542b\u307e\u308c\u308b\u300c\u5358\u8a9e\u300d\u3092\u8f9e\u66f8\u9806\u306b\u4e26\u3079\u3066\u3001\u51fa\u73fe\u3057\u305f\u884c\u756a\u53f7\u3068\u4e00\u7dd2\u306b\u51fa\u529b\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3002Scala \u3067\u3002<br \/>\n<script src=\"https:\/\/gist.github.com\/972887.js?file=WordCount.scala\"><\/script><noscript><pre><code class=\"language-scala scala\">object WordCount extends Application {\n  val lines = io.Source.fromInputStream(System.in).getLines\n\n  val dict = (for((line, i) &lt;- lines.zipWithIndex;\n      word &lt;- &quot;&quot;&quot;(\\w+)&quot;&quot;&quot;.r.findAllIn(line)) yield (word, i+1)\n  ).toList.groupBy {  _._1 }\n\n  dict.keys.toList.sorted foreach { key =&gt;\n    println(&quot;%-16s%s&quot;.format(key, dict(key) map { _._2 } mkString(&quot; &quot;)))\n  }\n}<\/code><\/pre><\/noscript><\/p>\n<p>\u5b9f\u884c\u4f8b\u3002<\/p>\n<script src=\"https:\/\/gist.github.com\/972887.js?file=output.txt\"><\/script><noscript><pre><code class=\"language-text text\">$ scala WordCount &lt; WordCount.scala\n1               7\n16s             11\nApplication     2\nSource          4\nSystem          4\nWordCount       2\n_               8 11\n_1              8\n_2              11\ndict            6 10 11\nextends         2\nfindAllIn       7\nfor             6\nforeach         10\nformat          11\nfromInputStream 4\ngetLines        4\ngroupBy         8\ni               6 7\nin              4\nio              4\nkey             10 11 11\nkeys            10\nline            6 7\nlines           4 6\nmap             11\nmkString        11\nobject          2\nprintln         11\nr               7\ns               11\nsorted          10\ntoList          8 10\nval             4 6\nw               7\nword            7 7\nyield           7\n<\/code><\/pre><\/noscript>\n","protected":false},"excerpt":{"rendered":"<p>stdin \u304b\u3089\u306e\u5165\u529b\u306b\u542b\u307e\u308c\u308b\u300c\u5358\u8a9e\u300d\u3092\u8f9e\u66f8\u9806\u306b\u4e26\u3079\u3066\u3001\u51fa\u73fe\u3057\u305f\u884c\u756a\u53f7\u3068\u4e00\u7dd2\u306b\u51fa\u529b\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3002Scala \u3067\u3002 object WordCount extends Application { val lines =  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,23],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/posts\/2783"}],"collection":[{"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2783"}],"version-history":[{"count":13,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/posts\/2783\/revisions"}],"predecessor-version":[{"id":2791,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/posts\/2783\/revisions\/2791"}],"wp:attachment":[{"href":"https:\/\/blog.tksk.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}