-
Notifications
You must be signed in to change notification settings - Fork 44
/
AipKg.php
189 lines (150 loc) · 5.36 KB
/
AipKg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipKg extends AipBase {
/**
* 创建任务 create_task api url
* @var string
*/
private $createTaskUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_create';
/**
* 更新任务 update_task api url
* @var string
*/
private $updateTaskUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_update';
/**
* 获取任务详情 task_info api url
* @var string
*/
private $taskInfoUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_info';
/**
* 以分页的方式查询当前用户所有的任务信息 task_query api url
* @var string
*/
private $taskQueryUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_query';
/**
* 启动任务 task_start api url
* @var string
*/
private $taskStartUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_start';
/**
* 查询任务状态 task_status api url
* @var string
*/
private $taskStatusUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_status';
/**
* 创建任务接口
*
* @param string $name - 任务名字
* @param string $templateContent - json string 解析模板内容
* @param string $inputMappingFile - 抓取结果映射文件的路径
* @param string $outputFile - 输出文件名字
* @param string $urlPattern - url pattern
* @param array $options - 可选参数对象,key: value都为string类型
* @description options列表:
* limit_count 限制解析数量limit_count为0时进行全量任务,limit_count>0时只解析limit_count数量的页面
* @return array
*/
public function createTask($name, $templateContent, $inputMappingFile, $outputFile, $urlPattern, $options=array()){
$data = array();
$data['name'] = $name;
$data['template_content'] = $templateContent;
$data['input_mapping_file'] = $inputMappingFile;
$data['output_file'] = $outputFile;
$data['url_pattern'] = $urlPattern;
$data = array_merge($data, $options);
return $this->request($this->createTaskUrl, $data);
}
/**
* 更新任务接口
*
* @param integer $id - 任务ID
* @param array $options - 可选参数对象,key: value都为string类型
* @description options列表:
* name 任务名字
* template_content json string 解析模板内容
* input_mapping_file 抓取结果映射文件的路径
* url_pattern url pattern
* output_file 输出文件名字
* @return array
*/
public function updateTask($id, $options=array()){
$data = array();
$data['id'] = $id;
$data = array_merge($data, $options);
return $this->request($this->updateTaskUrl, $data);
}
/**
* 获取任务详情接口
*
* @param integer $id - 任务ID
* @param array $options - 可选参数对象,key: value都为string类型
* @description options列表:
* @return array
*/
public function getTaskInfo($id, $options=array()){
$data = array();
$data['id'] = $id;
$data = array_merge($data, $options);
return $this->request($this->taskInfoUrl, $data);
}
/**
* 以分页的方式查询当前用户所有的任务信息接口
*
* @param array $options - 可选参数对象,key: value都为string类型
* @description options列表:
* id 任务ID,精确匹配
* name 中缀模糊匹配,abc可以匹配abc,aaabc,abcde等
* status 要筛选的任务状态
* page 页码
* per_page 页码
* @return array
*/
public function getUserTasks($options=array()){
$data = array();
$data = array_merge($data, $options);
return $this->request($this->taskQueryUrl, $data);
}
/**
* 启动任务接口
*
* @param integer $id - 任务ID
* @param array $options - 可选参数对象,key: value都为string类型
* @description options列表:
* @return array
*/
public function startTask($id, $options=array()){
$data = array();
$data['id'] = $id;
$data = array_merge($data, $options);
return $this->request($this->taskStartUrl, $data);
}
/**
* 查询任务状态接口
*
* @param integer $id - 任务ID
* @param array $options - 可选参数对象,key: value都为string类型
* @description options列表:
* @return array
*/
public function getTaskStatus($id, $options=array()){
$data = array();
$data['id'] = $id;
$data = array_merge($data, $options);
return $this->request($this->taskStatusUrl, $data);
}
}