<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yukun&#039;s Blog &#187; Chatterbot</title>
	<atom:link href="http://www.yukun.info/blog/tag/chatterbot/feed" rel="self" type="application/rss+xml" />
	<link>http://www.yukun.info</link>
	<description>難しいことは分かりやすく、簡単なことは面白く紹介</description>
	<lastBuildDate>Thu, 26 Jan 2012 03:33:59 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>人工無脳を作ってみる (1)入力文の末尾に文字列を追加</title>
		<link>http://www.yukun.info/blog/2008/11/implement-chatterbot-append-suffix.html</link>
		<comments>http://www.yukun.info/blog/2008/11/implement-chatterbot-append-suffix.html#comments</comments>
		<pubDate>Sun, 02 Nov 2008 15:00:46 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Chatterbot]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1233</guid>
		<description><![CDATA[さて、最初は単純にユーザの入力文の末尾に予め定義されている文字列を付け足して応答するだけのものです。 ソースコード package info.yukun.chatterbot; import java.io.Buffer &#8230; <a href="http://www.yukun.info/blog/2008/11/implement-chatterbot-append-suffix.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/11/implement-chatterbot-append-suffix.html">人工無脳を作ってみる (1)入力文の末尾に文字列を追加</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>さて、最初は単純にユーザの入力文の末尾に予め定義されている文字列を付け足して応答するだけのものです。</p>
<h3>ソースコード</h3>
<pre>
package info.yukun.chatterbot;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class SimpleChatterBot {
  private String botName = &quot;chatterbot&quot;;
  private String callStr = &quot;なにかしゃべってよ(&gt;_&lt;)&quot;;
  private String[] suffixResponses = {
    &quot;ってアレですね、わかります(^^)b&quot;,
    &quot;ですか？わかりません(&gt;_&lt;)&quot;,
    &quot;って何？日本語でおk(&#039;`)b&quot;};

  public void go() {
    try {
      BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
      System.out.print(&quot;INPUT : &quot;);
      String response;
      String input;
      while ((input = stdReader.readLine()) != null) { // ユーザの入力待ち
        if (input.equals(&quot;&quot;)) { // 入力が無かった
          response = callStr;
        } else {
          response = decorateInput(input) + getSuffixResponse();
        }
        System.out.print(botName + &quot;: &quot; + response);
        System.out.print(&quot;\nINPUT : &quot;);
      }
      stdReader.close();
      System.out.println(&quot;\nPROGRAM END&quot;);
    } catch (Exception e) {
      e.getStackTrace();
      System.exit(-1); // プログラムを終了
    }
  }

  private String getSuffixResponse() {
    int rand = (int) (Math.random() * suffixResponses.length);
    return suffixResponses[rand];
  }

  private String decorateInput(String input) {
    return &quot;「&quot; + input + &quot;」&quot;;
  }

  public static void main(String[] args) {
    SimpleChatterBot bot = new SimpleChatterBot();
    bot.go();
  }
}
</pre>
<p>getSuffixResponse()メソッド内で使われているMath.random()は、<br />
<blockquote cite="http://sdc.sun.co.jp/java/docs/j2se/1.4/ja/docs/ja/api/java/lang/Math.html" title="Math (Java 2 プラットフォーム SE v1.4.0)">static double random()<br />
0.0 以上で、1.0 より小さい正の符号の付いた double 値を返します。</p></blockquote>
<p>ですので、「Math.random() * 配列の長さ」 は「0～配列の長さ-1」 を意味します。</p>
<h3>実行結果の例</h3>
<pre>
INPUT : こんにちは
chatterbot: 「こんにちは」って何？日本語でおk('`)b
INPUT : え、
chatterbot: 「え、」ですか？わかりません(>_<)
INPUT : いえ、聞き返しただけです。
chatterbot: 「いえ、聞き返しただけです。」って何？日本語でおk('`)b
INPUT :
chatterbot: なにかしゃべってよ(>_<)
INPUT : 最近どうですか？
chatterbot: 「最近どうですか？」ってアレですね、わかります(^^)b
INPUT :
PROGRAM END
</pre>
<p>なんだかー、それはかとなくばかにしていますねf^^;</p>
<p>最初はJavaで書いていきますが、実装する機能の種類やリリースする環境によっては恐らく途中でOOをサポートする他の言語に変更するかも。<br />
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/11/java-user-system-in-inputstream-read.html" rel="bookmark" title="2008年11月2日">Java: ユーザからの(標準)入力を取得 &#8211; System.inとInputStreamReaderクラス</a></li>
<li><a href="http://www.yukun.info/blog/2008/03/diff-java-ruby-string.html" rel="bookmark" title="2008年3月4日">JavaとRubyで文字列の終端の扱いの違い</a></li>
<li><a href="http://www.yukun.info/blog/2008/05/java-strip.html" rel="bookmark" title="2008年5月29日">Java: 文字列の先頭・末尾の文字を削除するstrip()メソッド</a></li>
<li><a href="http://www.yukun.info/blog/2008/05/java-intersection.html" rel="bookmark" title="2008年5月20日">検索エンジンを実装 (4)AND演算</a></li>
<li><a href="http://www.yukun.info/blog/2010/05/java-networkinterface-ipv6-ipv4.html" rel="bookmark" title="2010年5月16日">Java: インターフェースとローカルのIPv6, IPv4アドレスの取得 &#8211; NetworkInterfaceクラス</a></li>
</ul>
<p><!-- Similar Posts took 7.229 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/11/implement-chatterbot-append-suffix.html">人工無脳を作ってみる (1)入力文の末尾に文字列を追加</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/11/implement-chatterbot-append-suffix.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>チャットログから本文を抽出</title>
		<link>http://www.yukun.info/blog/2007/04/chatlog.html</link>
		<comments>http://www.yukun.info/blog/2007/04/chatlog.html#comments</comments>
		<pubDate>Tue, 10 Apr 2007 10:54:00 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Chatterbot]]></category>
		<category><![CDATA[RegExp]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://codeai.net/?p=49</guid>
		<description><![CDATA[先日、メッセンジャーのチャットで会話するボットを作りました。 そのボットに「学習」させるネタに、会話文であるWindows Live Messengerのチャットログを用いることにしました。しかし、ログはXML形式なので &#8230; <a href="http://www.yukun.info/blog/2007/04/chatlog.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2007/04/chatlog.html">チャットログから本文を抽出</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>先日、メッセンジャーのチャットで会話するボットを作りました。 そのボットに「学習」させるネタに、会話文であるWindows Live Messengerのチャットログを用いることにしました。しかし、ログはXML形式なので、本文以外の余計なタグがはいっています。<br />
まあ、エディタで不用な部分を置換していっても良いのですが&#8230;</p>
<h4>抽出処理をRubyで自動化</h4>
<blockquote><p>仮に1時間かかる単調作業をするとしたら、私は50分かけても、その作業をこなすスクリプトを書く。</p></blockquote>
<p>と言う言葉を思いだしたので、早速、Windows Live Messenger(前MSN)のチャットログから本文のみを抽出するコードを書いてみました。</p>
<pre>
#! ruby -Ks
require ‘kconv’
MSNRegexp =/(.*?)&lt;.Text&gt;/xm
data = ""
filename = ARGV[0]
begin
  open(filename) do |f|
    f.each do |line| # ファイルから1行ずつ読む
    line = Kconv.kconv(line, Kconv::SJIS) # 文字コードを変換
    line.chomp!
    next if line.empty?
    data.concat(line)
  end
end
rescue => e
  puts(e.message)
end
open(’msnLog.txt’, ‘w’) do |f| # 出力ファイル
data.scan(MSNRegexp){|tdata|
  if tdata
    f.puts(tdata)
  end
}
end
</pre>
<p>上記のコードをプロンプトで抽出したいファイル名を引数に与えて 実行すると、msnLog.txtというファイルに本文が抽出されます。発言者なども抽出したい場合は、正規表現の部分を修正すれば良いですね。</p>
<p>では、今し方学習したボットとの会話はこんなです。 「<a href="http://www.yukun.info/blog/2007/04/chatbot-log.html" title="人工無脳とのチャットログ">とあるボットのチャットログ</a>」 やってる本人は、結構楽しんでましたね＾＾；と言うか合せてました。</p>
<h4>今後の改良点</h4>
<p>当面の課題は、辞書のメンテツールの作成及びデータベース化、人格形成、文脈・話者理解と情報収集・加工機能を利用環境に合せたエージェント化とか(ぅぉぃ)。</p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2007/04/chatbot-log.html" rel="bookmark" title="2007年4月10日">とあるボットのチャットログ</a></li>
<li><a href="http://www.yukun.info/blog/2008/02/ruby-excite-translation.html" rel="bookmark" title="2008年2月8日">POSTメソッドを用いてExcite翻訳を行うRubyコード</a></li>
<li><a href="http://www.yukun.info/blog/2008/02/extract-web-tag.html" rel="bookmark" title="2008年2月10日">Webページから指定したタグの要素を抜き出すRuby関数</a></li>
<li><a href="http://www.yukun.info/blog/2008/05/java-excite-translation.html" rel="bookmark" title="2008年5月16日">JavaプログラムからExcite翻訳を利用</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html" rel="bookmark" title="2008年10月7日">ActionScript: XMLの子要素の読み込み &#8211; XMLオブジェクトと「.. 」「[]」演算子</a></li>
</ul>
<p><!-- Similar Posts took 9.824 ms --></p>
<p><a href="http://www.yukun.info/blog/2007/04/chatlog.html">チャットログから本文を抽出</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2007/04/chatlog.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>とあるボットのチャットログ</title>
		<link>http://www.yukun.info/blog/2007/04/chatbot-log.html</link>
		<comments>http://www.yukun.info/blog/2007/04/chatbot-log.html#comments</comments>
		<pubDate>Tue, 10 Apr 2007 10:37:00 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Chatterbot]]></category>
		<category><![CDATA[Days]]></category>

		<guid isPermaLink="false">http://codeai.net/?p=48</guid>
		<description><![CDATA[人工無脳とのチャットログ yukun> こんにちはbot > こんちはyukun> 元気してた？bot > 元気に、そう見えても、おかしくはないがね。yukun> そうかbot > でしゃばりすぎだゼバーン!!yukun &#8230; <a href="http://www.yukun.info/blog/2007/04/chatbot-log.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2007/04/chatbot-log.html">とあるボットのチャットログ</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>人工無脳とのチャットログ</p>
<blockquote><p>yukun> こんにちは<br />bot  > こんちは<br />yukun> 元気してた？<br />bot  > 元気に、そう見えても、おかしくはないがね。<br />yukun> そうか<br />bot  > でしゃばりすぎだゼバーン!!<br />yukun> ぐわー！やられた・・・<br />bot  > 自我があって、次のステップにいけなくなって、またねー<br />yukun> その自我とは？<br />bot  > 自我になりえると思うよ<br />yukun> 今日は人工知能と自我について話そうぜ<br />bot  > 何というか人間の思考を模倣することと自我とは全くの別問題だと思うのだよ？<br />yukun> ほんとにそう思う?<br />bot  > 人工知能とかよりも早く義体できないかなぁとか思ってしまうな<br />yukun> え、あぁ義体ねぇ。つけてみたいか？<br />bot  > 義だけ聞くと、ありがちな体ではあるね。<br />yukun> そうなのか。そんな体が在ったとは…<br />bot  > かわいー！<br />yukun> お前さん、特殊な感性をしているな<br />bot  > お前らと出会うことになるね、人間らしい考え方のプロセスを持つものは出来るけど、それの宇宙版なんだ。<br />yukun> もう、どう突っ込んでよいか…人間らしい思考のプロセスって具体的に何だろうね。<br />bot  > わかればいいんだけどさ<br />yukun> わからないか？<br />bot  > 違うよ…<br />yukun> と言いますと…<br />bot  > じゃあこれ知ってる？<br />yukun> 何でしょう<br />bot  > 何はわからん<br />yukun> 焦らし過ぎだから、残念！<br />bot  > 残念なことに質問型の人工知能には、こっつちの質問できることにリストが必要だからね<br />yukun> 必要なら、学習させれば良いじゃないか<br />bot  > な、なんだってー！？<br />yukun> まぁ、機械学習にも色々あるが、できないことはない<br />bot  > IF-THEN型の学習ではフレーム問題に行き着くね。<br />yukun> お、なかなかどうして良いタイミングで鋭いことを言うじゃないか<br />bot  > どんなタイミング型？<br />yukun> IF-THEN型のタイミングさ<br />bot  > IF-THENは見てるタイミングない<br />yukun> 見るんじゃない、感じるんだ<br />bot  > そんな感じw<br />yukun> マジか、ついに感性！？んなアホな</p></blockquote>
<p>所々、文法が崩れているところがありますが、まぁ、予想の範囲です。</p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2007/04/chatlog.html" rel="bookmark" title="2007年4月10日">チャットログから本文を抽出</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/implement-chatterbot-append-suffix.html" rel="bookmark" title="2008年11月3日">人工無脳を作ってみる (1)入力文の末尾に文字列を追加</a></li>
<li><a href="http://www.yukun.info/blog/2008/08/announcement-change-site-url.html" rel="bookmark" title="2008年8月8日">サイトURLの変更のお知らせ</a></li>
<li><a href="http://www.yukun.info/blog/2007/08/protein-fortune-telling.html" rel="bookmark" title="2007年8月26日">たんぱく質うらない</a></li>
<li><a href="http://www.yukun.info/blog/2007/09/second-stage.html" rel="bookmark" title="2007年9月21日">今日から後期開始</a></li>
</ul>
<p><!-- Similar Posts took 8.589 ms --></p>
<p><a href="http://www.yukun.info/blog/2007/04/chatbot-log.html">とあるボットのチャットログ</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2007/04/chatbot-log.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

