使用PHP从Wikidata提取数据
我用伪造者来产生人,我想使用wikidata做同样的事情。通过获取名称,出生日期,性别,第一段和其他指定的类似数据。此外,还可以通过检查现有人员(例如Q4926)来避免重复。 wikidata query = https://w.wiki/5lur
是否可以使用 freearhey/wikidata 或 addwiki/wikibase-api 或应该 query.wikidata.org/sparql
当前使用的代码段
if ($s == 'generate_fake_users') {
require "assets/libraries/fake-users/vendor/autoload.php";
$faker = Faker\Factory::create();
if (empty($_POST['password'])) {
$_POST['password'] = '123456789';
}
$count_users = $_POST['count_users'];
$password = $_POST['password'];
$avatar = $_POST['avatar'];
ob_end_clean();
header("Content-Encoding: none");
header("Connection: close");
ignore_user_abort();
ob_start();
header('Content-Type: application/json');
echo json_encode(array(
'status' => 200
));
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();
flush();
session_write_close();
if (is_callable('fastcgi_finish_request')) {
fastcgi_finish_request();
}
for ($i=0; $i < $count_users; $i++) {
$genders = array_keys($wo['genders']);
$random_keys = array_rand($genders, 1);
$gender = array_rand(array("male", "female"), 1);
$gender = $genders[$random_keys];
$re_data = array(
'email' => Site_Secure(str_replace(".", "_", $faker->userName) . '_' . rand(111, 999) . "@domain.com", 0),
'username' => Site_Secure($faker->userName . '_' . rand(111, 999), 0),
'password' => Site_Secure($password, 0),
'email_code' => Site_Secure(md5($faker->userName . '_' . rand(111, 999)), 0),
'src' => 'Fake',
'gender' => Site_Secure($gender),
'lastseen' => time(),
'active' => 1,
'first_name' => $faker->firstName($gender),
'last_name' => $faker->lastName
);
if ($avatar == 1) {
$urls = array("http://lorempixel.com/".$wo['profile_picture_width_crop']."/".$wo['profile_picture_height_crop']."/people","https://placeimg.com/".$wo['profile_picture_width_crop']."/".$wo['profile_picture_height_crop']."/people");
$rand = rand(0,1);
$url = $urls[$rand];
$a = Site_ImportImageFromFile($url,'_url_image','avatar');
if (!empty($a)) {
$re_data['avatar'] = $a;
}
}
$add_user = Site_RegisterUser($re_data);
}
header("Content-type: application/json");
echo json_encode($data);
exit();
}
I have used Faker to generate persons and I want to do the same thing using Wikidata. By getting names, date of birth, gender, first paragraph and other specified similar data. In addition being able to avoid duplicates by checking existing persons (e.g Q4926) I have fetched before. Wikidata Query = https://w.wiki/5LUr
Is it possible to use freearhey/wikidata or addwiki/wikibase-api or should query.wikidata.org/sparql be used diretly
Code snippet currently used
if ($s == 'generate_fake_users') {
require "assets/libraries/fake-users/vendor/autoload.php";
$faker = Faker\Factory::create();
if (empty($_POST['password'])) {
$_POST['password'] = '123456789';
}
$count_users = $_POST['count_users'];
$password = $_POST['password'];
$avatar = $_POST['avatar'];
ob_end_clean();
header("Content-Encoding: none");
header("Connection: close");
ignore_user_abort();
ob_start();
header('Content-Type: application/json');
echo json_encode(array(
'status' => 200
));
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();
flush();
session_write_close();
if (is_callable('fastcgi_finish_request')) {
fastcgi_finish_request();
}
for ($i=0; $i < $count_users; $i++) {
$genders = array_keys($wo['genders']);
$random_keys = array_rand($genders, 1);
$gender = array_rand(array("male", "female"), 1);
$gender = $genders[$random_keys];
$re_data = array(
'email' => Site_Secure(str_replace(".", "_", $faker->userName) . '_' . rand(111, 999) . "@domain.com", 0),
'username' => Site_Secure($faker->userName . '_' . rand(111, 999), 0),
'password' => Site_Secure($password, 0),
'email_code' => Site_Secure(md5($faker->userName . '_' . rand(111, 999)), 0),
'src' => 'Fake',
'gender' => Site_Secure($gender),
'lastseen' => time(),
'active' => 1,
'first_name' => $faker->firstName($gender),
'last_name' => $faker->lastName
);
if ($avatar == 1) {
$urls = array("http://lorempixel.com/".$wo['profile_picture_width_crop']."/".$wo['profile_picture_height_crop']."/people","https://placeimg.com/".$wo['profile_picture_width_crop']."/".$wo['profile_picture_height_crop']."/people");
$rand = rand(0,1);
$url = $urls[$rand];
$a = Site_ImportImageFromFile($url,'_url_image','avatar');
if (!empty($a)) {
$re_data['avatar'] = $a;
}
}
$add_user = Site_RegisterUser($re_data);
}
header("Content-type: application/json");
echo json_encode($data);
exit();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论