for ($i = 0; $i < count($ary); $i++) { $str = $ary[$i]["word"]; array_push($words, $str); } array_push($words, "EOS"); ?> <div id="chat-frame"> <p class="chat-talk"> <span class="talk-icon"> <img src="tehuimg.jpg" alt="tartgeticon" width="50" height="50"/> </span> <span class="talk-content"> <?php $summary = $summarizer->summarize($words, 3); echo $summary; ?> <br /> <a href="https://twitter.com/share" class="twitter-share-button"{count} data-text="<?php echo mb_strimwidth($summary, 0, 200, '…', 'UTF-8'); ?> ">Tweet</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> </span></div> <div style="margin-top:20px">※ <a href=".">リロード</a>する度に名言は変わります</div> <hr> </main>
' . PHP_EOL; $summarizer = new Markov(); $words = array(); $fn = "./" . hash("sha1", $string); if (file_exists($fn)) { $words = unserialize(file_get_contents($fn)); } else { $mecab = new Mecabp(); $ary = $mecab->parse($string); for ($i = 0; $i < count($ary); $i++) { $str = $ary[$i]["word"]; if ($ary[$i]["kind"] == "名詞") { $str = "<span style='font-weight:bold; font-size:20px;'>" . $str . "</span>"; } array_push($words, $str); } array_push($words, "EOS"); file_put_contents($fn, serialize($words)); } $time_start = microtime(true); echo $summarizer->summarize($words, 3); $timelimit = microtime(true) - $time_start; ?> <div style="margin-top:20px">※ <a href=".">リロード</a>する度に文章は変わります</div> <hr /> MeCabによる形態素解析→マルコフ連鎖テスト <a href="https://github.com/hbkr/markov">github</a> / <a href="http://twitter.com/hbkr">twitter</a> </body> </html>