ユーザとエージェントの間を取り持つエージェントについて説明します.教科書p.66 "3.4 人間とエージェントとの通信を支援する" の内容に相当します.
(3.2節と同じ)
class DB_access extends TAG { def loop(msg) { println msg if (msg._p=='from-user' && msg.whereis!=null) { // 所在地の問合せ Map m = request('ODB_aomori', [_p:'request-information', name:msg.whereis]) reply(msg, [_p:'to-user', name:m.name, city:m.city]) } else if (msg._p=='from-user' && msg.whattype!=null) { // 泉質の問合せ Map m = request('ODB_aomori', [_p:'request-information', name:msg.whattype]) reply(msg, [_p:'to-user', name:m.name, type:m.type]) } else { reply(msg, [_p:'sorry', msg:msg]) } } }
request()
を使うと,他のエージェントに問い合わせを行い,回答を得ることができます.[_p:'from-user', whereis:'湯野川温泉']
を送ると,次のデータが返ってきます:[_p:'to-user', name:'湯野川温泉', city:'川内町', _f:'DB_access']
[_p:'from-user', whattype:'湯野川温泉']
を送ると,次のデータが返ってきます:[_p:'to-user', name:'湯野川温泉', type:'単純泉', _f:'DB_access']