Пример #1
0
 public function execute($message)
 {
     $cmd = strtolower($message->getCommand());
     $data = $message->getData();
     $params = array("format" => "plaintext");
     $wa = new WolframAlphaEngine(WOLFRAM_API_KEY);
     $res = $wa->getResults(implode(" ", $data), $params);
     file_put_contents("log/wolfram.log", json_encode($res));
     $sol = array();
     if ($res->isError()) {
         Api::reply($message, "Da kann ich leider nichts mit anfangen...", false);
         return;
     }
     if (count($res->getPods()) > 0) {
         foreach ($res->getPods() as $pod) {
             if ($pod->attributes["id"] == "Solution") {
                 $sol[] = "*Ergebnisse für " . implode(" ", $data) . "*:";
                 foreach ($pod->getSubpods() as $solution) {
                     $sol[] = api::encodePlain($solution->plaintext);
                 }
             } elseif ($pod->attributes["id"] == "ComplexSolution") {
                 $sol[] = "*Komplexe Ergebnisse für " . implode(" ", $data) . "*:";
                 foreach ($pod->getSubpods() as $solution) {
                     $sol[] = api::encodePlain($solution->plaintext);
                 }
             } elseif ($pod->attributes["id"] == "Result") {
                 $sol[] = "*Ergebnis für " . implode(" ", $data) . "*:";
                 foreach ($pod->getSubpods() as $solution) {
                     $sol[] = api::encodePlain($solution->plaintext);
                 }
             }
         }
     }
     if (sizeof($sol) == 0) {
         $sol[] = "Leider keine Ergebnisse :(";
     }
     Api::reply($message->chat, implode("\n", $sol), true);
 }
Пример #2
0
include 'easter.php';
if (!$queryIsSet) {
    die;
}
foreach ($hardBoiledEggs as $egg => $yolk) {
    if (strpos(strtolower($q), strtolower($egg)) !== false) {
        echo "Interpretted as: {$egg} | \nAnswer: {$yolk}";
        die;
    }
}
$qArgs = array();
if (isset($_REQUEST['assumption'])) {
    $qArgs['assumption'] = $_REQUEST['assumption'];
}
// instantiate an engine object with your app id
$engine = new WolframAlphaEngine($config['appID']);
// we will construct a basic query to the api with the input 'pi'
// only the bare minimum will be used
$response = $engine->getResults($q, $qArgs);
if ($response->isError()) {
    echo "Sorry looks like there was a problem with the query. Maybe we're out of queries this month?";
    die;
}
$pods = $response->getPods();
if (count($pods) > 0) {
    $questionSubpods = $pods[0]->getSubpods();
    $answerSubpods = $pods[1]->getSubpods();
    echo "Interpretted as: " . $questionSubpods[0]->plaintext . " | \n";
    echo "Answer: " . $answerSubpods[0]->plaintext . "\n";
} else {
    foreach ($softBoiledEggs as $egg => $yolk) {
Пример #3
0
"
>&nbsp;&nbsp; <input type="submit" name="Search" value="Search">
</form>
<br><br>
<hr>
<?php 
$appID = 'G4UT54-4ETKTTH58Y';
if (!$queryIsSet) {
    die;
}
$qArgs = array();
if (isset($_REQUEST['assumption'])) {
    $qArgs['assumption'] = $_REQUEST['assumption'];
}
// instantiate an engine object with your app id
$engine = new WolframAlphaEngine($appID);
// we will construct a basic query to the api with the input 'pi'
// only the bare minimum will be used
$response = $engine->getResults($_REQUEST['q'], $qArgs);
// getResults will send back a WAResponse object
// this object has a parsed version of the wolfram alpha response
// as well as the raw xml ($response->rawXML)
// we can check if there was an error from the response object
if ($response->isError()) {
    ?>
  <h1>There was an error in the request</h1>
  </body>
  </html>
<?php 
    die;
}
Пример #4
0
<?php

include 'WolframAlphaEngine.php';
$appID = '';
// instantiate an engine object with your app id
$engine = new WolframAlphaEngine($appID);
$query = !empty($_REQUEST['q']) ? $_REQUEST['q'] : 'Population of Canada';
// we will construct a basic query to the api with the input 'pi' only the bare minimum will be used
$response = $engine->getResults($query);
// getResults will send back a WAResponse object, this object has a parsed version of the wolfram alpha response as well as the raw xml ($response->rawXML)
?>
<html>
<body>
<form method='POST' action='#'>
Search: <input type="text" name="q" value="<?php 
echo $query;
?>
">&nbsp;&nbsp; <input type="submit" name="Search" value="Search">
</form>
<br><br>
<hr>
<?php 
// we can check if there was an error from the response object
if ($response->isError) {
    ?>
  <h1>There was an error in the request</h1>
  </body>
  </html>
<?php 
    die;
}
Пример #5
0
<?php

/**
 * Created by PhpStorm.
 * User: Farzan
 * Date: 9/4/2015
 * Time: 5:34 PM
 */
header("Access-Control-Allow-Origin: *");
include 'assets\\lib\\wa_wrapper\\WolframAlphaEngine.php';
$response = 'Nothing here';
$appID = 'API-CODE-GOES-HERE';
$qArgs = array();
if (isset($_GET['str'])) {
    // echo json_encode($_GET['str']);
    $engine = new WolframAlphaEngine($appID);
    $response = $engine->getResults($_GET['str'], $qArgs);
    $ans = array();
    //echo json_encode($response);
    //the if to see if the request suceeded:
    if ($response->attributes['success']) {
        if (count($response->getPods()) > 0) {
            foreach ($response->getPods() as $pod) {
                array_push($ans, $pod->attributes['title']);
                // each pod can contain multiple sub pods but must have at least one
                foreach ($pod->getSubpods() as $subpod) {
                    // if format is an image, the subpod will contain a WAImage object
                    //echo '"'.$subpod->image->attributes['src'].'",';
                    array_push($ans, $subpod->image->attributes['src']);
                }
            }