public function Emotion()
 {
     $this->init();
     $uqq = I('get.uqq');
     //$uqq = 136787510;
     $where = array('uin' => $uqq);
     $ssLogic = D('Shuoshuo', 'Logic');
     $friendShuoShuo = M('friend_shuoshuo');
     $shuoshuoAll = $ssLogic->getShuoshuoAll($where);
     consoleShow("文本分类,情感分析开始");
     Vendor('QcloudApi.QcloudApi');
     $service = \QcloudApi::load(\QcloudApi::MODULE_WENZHI, C("QcloudApi"));
     $method = 'POST';
     $service->setConfigRequestMethod($method);
     $classArr = $ssLogic::getTextClassArr();
     foreach ($shuoshuoAll as $k => $v) {
         $content = $v['summary'];
         if (!$content) {
             continue;
         }
         $where['cellid'] = $v['cellid'];
         if (!$v['class_code']) {
             //文本分类
             $request = $service->TextClassify(array("content" => $content));
             if ($request === false) {
                 $error = $service->getError();
                 consoleShow("Class Error code class_code:" . $error->getCode());
                 consoleShow("message:" . $error->getMessage());
                 consoleShow("ext:" . var_export($error->getExt(), true));
             } else {
                 $classCode = array();
                 $classConf = array();
                 foreach ($request['classes'] as $v2) {
                     if ($v2['class_num'] < 10) {
                         $code = "0X0000000" . $v2['class_num'];
                     } else {
                         $code = "0X000000" . strtoupper(dechex($v2['class_num']));
                     }
                     if (!isset($classArr[$code])) {
                         consoleShow("未存在的分类:" . $code);
                     }
                     $classCode[] = $code;
                     $classConf[] = $v2['conf'];
                 }
                 $upDateArr = array('class_code' => implode(",", $classCode), 'class_conf' => implode(",", $classConf));
                 $friendShuoShuo->where($where)->save($upDateArr);
             }
         }
         if (!$v['positive']) {
             //情感分析
             $request = $service->TextSentiment(array("content" => $content));
             if ($request === false) {
                 $error = $service->getError();
                 consoleShow("Class Error code:positive " . $error->getCode());
                 consoleShow("message:" . $error->getMessage());
                 consoleShow("ext:" . var_export($error->getExt(), true));
             } else {
                 $upDateArr = array('positive' => round($request['positive'], 4));
                 $friendShuoShuo->where($where)->save($upDateArr);
             }
         }
         consoleShow("处理记录:" . mb_substr($content, 0, 15, 'utf-8'));
     }
     consoleShow("文本分类,情感分析处理完毕");
     consoleShow("<script>parent.emotionOver(" . $uqq . ")</script>");
 }
Beispiel #2
0
<?php

error_reporting(E_ALL ^ E_NOTICE);
require_once './src/QcloudApi/QcloudApi.php';
$config = array('SecretId' => 'AKIDCcU7DB3HdvnYqspxLosnLF9HnJkI8gn3', 'SecretKey' => 'y2YmUlKVPbWmm0fQbxmEGz0Nj3wgWysM', 'RequestMethod' => 'POST', 'DefaultRegion' => 'gz');
$wenzhi = QcloudApi::load(QcloudApi::MODULE_WENZHI, $config);
$package = array("content" => "李亚鹏挺王菲:加油!孩儿他娘。");
$a = $wenzhi->TextSentiment($package);
if ($a === false) {
    $error = $wenzhi->getError();
    echo "Error code:" . $error->getCode() . ".\n";
    echo "message:" . $error->getMessage() . ".\n";
    echo "ext:" . var_export($error->getExt(), true) . ".\n";
} else {
    var_dump($a);
}
echo "\nRequest :" . $wenzhi->getLastRequest();
echo "\nResponse :" . $wenzhi->getLastResponse();
echo "\n";
Beispiel #3
0
<?php

error_reporting(E_ALL ^ E_NOTICE);
require_once './src/QcloudApi/QcloudApi.php';
$config = array('SecretId' => '你的secretId', 'SecretKey' => '你的secretKey', 'RequestMethod' => 'GET', 'DefaultRegion' => 'gz');
$cvm = QcloudApi::load(QcloudApi::MODULE_CVM, $config);
$package = array('offset' => 0, 'limit' => 3);
$a = $cvm->DescribeInstances($package);
// $a = $cvm->generateUrl('DescribeInstances', $package);
if ($a === false) {
    $error = $cvm->getError();
    echo "Error code:" . $error->getCode() . ".\n";
    echo "message:" . $error->getMessage() . ".\n";
    echo "ext:" . var_export($error->getExt(), true) . ".\n";
} else {
    var_dump($a);
}
echo "\nRequest :" . $cvm->getLastRequest();
echo "\nResponse :" . $cvm->getLastResponse();
echo "\n";