コード例 #1
0
ファイル: Session.php プロジェクト: fabioued/ChatterBotApi
 /**
  * Return new thought based on given thought
  * @param  \ChatterBotApi\ChatterBotTought $thought The previous thought
  * @return \ChatterBotApi\ChatterBotTought          The new thought.
  *
  * @throws \Exception If response is empty (when input string is empty)
  */
 public function thinkThought(ChatterBotThought $thought)
 {
     $this->vars['input'] = $thought->getText();
     $response = Utils::post('http://www.pandorabots.com/pandora/talk-xml', $this->vars);
     $element = new SimpleXMLElement($response);
     $result = $element->xpath('//result/that/text()');
     if (isset($result[0][0])) {
         return ChatterBotThought::make($result[0][0]);
     } else {
         throw new Exception('Empty Response');
     }
 }
コード例 #2
0
ファイル: Session.php プロジェクト: fabioued/ChatterBotApi
 /**
  * Return new thought based on given thought
  * @param  \ChatterBotApi\ChatterBotTought $thought The previous thought
  * @return \ChatterBotApi\ChatterBotTought          The new thought.
  */
 public function thinkThought(ChatterBotThought $thought)
 {
     $this->vars['stimulus'] = $thought->getText();
     $data = http_build_query($this->vars);
     $dataToDigest = substr($data, 9, 20);
     $dataDigest = md5($dataToDigest);
     $this->vars['icognocheck'] = $dataDigest;
     $response = Utils::post($this->bot->getUrl(), $this->vars);
     $responseValues = explode("\r", $response);
     // $this->vars['??']                    = Utils::stringAtIndex($responseValues, 0);
     $this->vars['sessionid'] = Utils::stringAtIndex($responseValues, 1);
     $this->vars['logurl'] = Utils::stringAtIndex($responseValues, 2);
     $this->vars['vText8'] = Utils::stringAtIndex($responseValues, 3);
     $this->vars['vText7'] = Utils::stringAtIndex($responseValues, 4);
     $this->vars['vText6'] = Utils::stringAtIndex($responseValues, 5);
     $this->vars['vText5'] = Utils::stringAtIndex($responseValues, 6);
     $this->vars['vText4'] = Utils::stringAtIndex($responseValues, 7);
     $this->vars['vText3'] = Utils::stringAtIndex($responseValues, 8);
     $this->vars['vText2'] = Utils::stringAtIndex($responseValues, 9);
     $this->vars['prevref'] = Utils::stringAtIndex($responseValues, 10);
     // $this->vars['??']                = Utils::stringAtIndex($responseValues, 11);
     $this->vars['emotionalhistory'] = Utils::stringAtIndex($responseValues, 12);
     $this->vars['ttsLocMP3'] = Utils::stringAtIndex($responseValues, 13);
     $this->vars['ttsLocTXT'] = Utils::stringAtIndex($responseValues, 14);
     $this->vars['ttsLocTXT3'] = Utils::stringAtIndex($responseValues, 15);
     $this->vars['ttsText'] = Utils::stringAtIndex($responseValues, 16);
     $this->vars['lineRef'] = Utils::stringAtIndex($responseValues, 17);
     $this->vars['lineURL'] = Utils::stringAtIndex($responseValues, 18);
     $this->vars['linePOST'] = Utils::stringAtIndex($responseValues, 19);
     $this->vars['lineChoices'] = Utils::stringAtIndex($responseValues, 20);
     $this->vars['lineChoicesAbbrev'] = Utils::stringAtIndex($responseValues, 21);
     $this->vars['typingData'] = Utils::stringAtIndex($responseValues, 22);
     $this->vars['divert'] = Utils::stringAtIndex($responseValues, 23);
     if ('' == Utils::stringAtIndex($responseValues, 16)) {
         throw new Exception('Empty Response');
     }
     return ChatterBotThought::make(Utils::stringAtIndex($responseValues, 16));
 }
コード例 #3
0
 You should have received a copy of the GNU Lesser General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * This tests were written by:
 * Christian Gärtner <*****@*****.**>
 */
require 'vendor/autoload.php';
use ChatterBotApi\ChatterBotType;
use ChatterBotApi\ChatterBotThought;
use ChatterBotApi\ChatterBotFactory;
$bot1 = ChatterBotFactory::create(ChatterBotType::CLEVERBOT);
$bot1session = $bot1->createSession();
$bot2 = ChatterBotFactory::create(ChatterBotType::PANDORABOTS, ChatterBotType::PANDORABOTS_DEFAULT_ID);
$bot2session = $bot2->createSession();
$th = ChatterBotThought::make('Hi');
while (1) {
    echo "bot1> {$th}\n";
    try {
        $th = $bot2session->think($th->message());
    } catch (IOException $e) {
        echo $e;
    } catch (Exception $e) {
        // Ignore these
    }
    echo "bot2> {$th}\n";
    try {
        $th = $bot1session->think($th->message());
    } catch (IOException $e) {
        echo $e;
    } catch (Exception $e) {
コード例 #4
0
 public function testMessage()
 {
     $t = ChatterBotThought::make('Foo');
     $this->assertEquals('Foo', $t->message());
 }