コード例 #1
0
ファイル: MessageApi.php プロジェクト: tgallice/wit-php
 /**
  * @param string $text
  * @param Context|null $context
  * @param array $queryParams
  *
  * @return mixed
  */
 public function extractMeaning($text, Context $context = null, array $queryParams = [])
 {
     $query = array_merge($queryParams, ['q' => $text]);
     if (null !== $context && !$context->isEmpty()) {
         $query['context'] = json_encode($context);
     }
     $response = $this->client->get('/message', $query);
     return $this->decodeResponse($response);
 }
コード例 #2
0
ファイル: SpeechApi.php プロジェクト: tgallice/wit-php
 /**
  * @param string|resource $file
  * @param array|null $context
  * @param array $queryParams
  *
  * @return array|null
  */
 public function extractMeaning($file, Context $context = null, array $queryParams = [])
 {
     if (!$file || !is_resource($file) && !is_readable($file)) {
         throw new \InvalidArgumentException('$file argument must be a readable file path or a valid resource');
     }
     if (null !== $context && !$context->isEmpty()) {
         $queryParams['context'] = json_encode($context);
     }
     $file = is_resource($file) ? $file : fopen($file, 'r');
     $response = $this->client->send('POST', '/speech', $file, $queryParams);
     return $this->decodeResponse($response);
 }
コード例 #3
0
ファイル: ConverseApi.php プロジェクト: tgallice/wit-php
 /**
  * @param string $sessionId
  * @param string|null $text
  * @param Context|null $context
  *
  * @return array
  */
 public function converse($sessionId, $text = null, Context $context = null)
 {
     $query = ['session_id' => $sessionId];
     if (!empty($text)) {
         $query['q'] = $text;
     }
     $body = null;
     // Don't send empty array
     if (null !== $context && !$context->isEmpty()) {
         $body = $context;
     }
     $response = $this->client->send('POST', '/converse', $body, $query);
     return $this->decodeResponse($response);
 }
コード例 #4
0
ファイル: EntityApi.php プロジェクト: tgallice/wit-php
 /**
  * @param string $entityId
  * @param EntityValue[] $entityValues
  * @param null|string $description
  * @param array $lookups
  *
  * @return mixed
  */
 public function create($entityId, array $entityValues = [], $description = null, array $lookups = [Entity::LOOKUP_KEYWORDS])
 {
     $data = ['id' => $entityId, 'values' => $entityValues, 'doc' => $description, 'lookups' => $lookups];
     $response = $this->client->post('/entities', $data);
     return $this->decodeResponse($response);
 }