|
...
|
...
|
@@ -81,9 +81,11 @@ class GeoQuestionRes extends Command |
|
|
|
GET_RESULT:
|
|
|
|
$error_num++;
|
|
|
|
try {
|
|
|
|
echo '执行次数:'.$error_num.PHP_EOL;
|
|
|
|
if ($error_num >= 5) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
echo '执行平台:'.$platform.PHP_EOL;
|
|
|
|
if ($platform == 'Google AI Overview') {
|
|
|
|
// overview 数据结构不确定, 需要单独处理数据
|
|
|
|
$data = $geo_service->getGooglePlatformResult($question);
|
|
...
|
...
|
@@ -201,42 +203,46 @@ class GeoQuestionRes extends Command |
|
|
|
'model' => 'Google AI Overview',
|
|
|
|
'text' => '',
|
|
|
|
];
|
|
|
|
if (FALSE == empty($data['ai_overview']['texts']) && is_array($data['ai_overview']['texts'])) {
|
|
|
|
if(!empty($data['data']['text_parts']) && is_array($data['data']['text_parts'])){
|
|
|
|
$texts = [];
|
|
|
|
foreach ($data['ai_overview']['texts'] as $item) {
|
|
|
|
// 提取链接
|
|
|
|
if (FALSE == empty($item['links'])) {
|
|
|
|
foreach ($item['links'] as $link) {
|
|
|
|
if (FALSE == empty($link['text']) && FALSE == empty($link['link'])) {
|
|
|
|
$result['annotations'][] = [
|
|
|
|
'type' => 'url_citation',
|
|
|
|
'url_citation' => [
|
|
|
|
'url' => $link['link'],
|
|
|
|
'title' => $link['text']
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($$data['data']['text_parts'] as $item){
|
|
|
|
if(empty($item['text'])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// 第一层就有内容
|
|
|
|
if (FALSE == empty($item['snippet'])) {
|
|
|
|
// title 放到数组最前面
|
|
|
|
if (FALSE == empty($item['type']) && $item['type'] == 'title')
|
|
|
|
array_unshift($texts, $item['snippet']);
|
|
|
|
else
|
|
|
|
array_push($texts, $item['snippet']);
|
|
|
|
switch ($item['type']){
|
|
|
|
case 'paragraph':
|
|
|
|
array_push($texts, $item['text']);
|
|
|
|
break;
|
|
|
|
case 'title':
|
|
|
|
array_unshift($texts, $item['text']);
|
|
|
|
break;
|
|
|
|
case 'list':
|
|
|
|
if(!empty($item['list'])){
|
|
|
|
foreach ($item['list'] as $sonItem){
|
|
|
|
array_push($texts, $sonItem['title']);
|
|
|
|
array_push($texts, $sonItem['text']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// list类型
|
|
|
|
if (FALSE == empty($item['type']) && $item['type'] == 'list' && FALSE == empty($item['list']) && is_array($item['list'])) {
|
|
|
|
foreach ($item['list'] as $list) {
|
|
|
|
if (FALSE == empty($list['snippet']))
|
|
|
|
array_push($texts, $list['snippet']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!empty($data['data']['reference_links']) && is_array($data['data']['reference_links'])){
|
|
|
|
foreach ($data['data']['reference_links'] as $link) {
|
|
|
|
if (!empty($link['text']) && !empty($link['link'])) {
|
|
|
|
$result['annotations'][] = [
|
|
|
|
'type' => 'url_citation',
|
|
|
|
'url_citation' => [
|
|
|
|
'url' => $link['link'],
|
|
|
|
'title' => $link['title']
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$text = implode(PHP_EOL, $texts);
|
|
|
|
$result['text'] = $text;
|
|
|
|
}
|
|
|
|
$text = implode(PHP_EOL, $texts);
|
|
|
|
$result['text'] = $text;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|