Improving wikidata included properties and values
This commit is contained in:
parent
f7707dea23
commit
1e246cdd1a
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Services\Wikidata;
|
namespace App\Services\Wikidata;
|
||||||
|
|
||||||
use App\Models\WikidataProperty;
|
use App\Models\WikidataProperty;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class WikidataExtractor
|
class WikidataExtractor
|
||||||
{
|
{
|
||||||
|
@ -115,7 +116,7 @@ private function browse(array $claims)
|
||||||
$newKey = $this->replaceValue($key, true, true);
|
$newKey = $this->replaceValue($key, true, true);
|
||||||
$excluded[$newKey] = $claim;
|
$excluded[$newKey] = $claim;
|
||||||
} elseif ($isIncluded) {
|
} elseif ($isIncluded) {
|
||||||
$newKey = $this->replaceValue($key, true);
|
// $newKey = $this->replaceValue($key, true);
|
||||||
$included[$key] = $claim;
|
$included[$key] = $claim;
|
||||||
} elseif ($isUnused) {
|
} elseif ($isUnused) {
|
||||||
$newKey = $this->replaceValue($key, true, true);
|
$newKey = $this->replaceValue($key, true, true);
|
||||||
|
@ -202,8 +203,11 @@ private function parseSnak(array $data, bool $parentIncluded)
|
||||||
case 'monolingualtext':
|
case 'monolingualtext':
|
||||||
$value = $value['text'];
|
$value = $value['text'];
|
||||||
break;
|
break;
|
||||||
|
case 'globecoordinate':
|
||||||
|
// Leave it as is
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return $data;
|
dd($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -216,15 +220,11 @@ private function parseSnak(array $data, bool $parentIncluded)
|
||||||
*/
|
*/
|
||||||
private function replaceValue(string $value, bool $showCode = true, bool $showLabel = true)
|
private function replaceValue(string $value, bool $showCode = true, bool $showLabel = true)
|
||||||
{
|
{
|
||||||
$isExcluded = in_array($value, $this->exclusions);
|
|
||||||
$isIncluded = in_array($value, collect($this->inclusions)->flatten()->values()->toArray());
|
|
||||||
$isUnused = !$isExcluded && !$isIncluded;
|
|
||||||
|
|
||||||
$code = $value;
|
$code = $value;
|
||||||
$label = $value;
|
$label = $value;
|
||||||
|
|
||||||
if (array_key_exists($value, $this->properties)) {
|
if (array_key_exists($value, $this->properties)) {
|
||||||
$label = $this->properties[$value];
|
$label = Str::ucfirst($this->properties[$value]);
|
||||||
} elseif (array_key_exists($value, $this->entities)) {
|
} elseif (array_key_exists($value, $this->entities)) {
|
||||||
$label = $this->entities[$value];
|
$label = $this->entities[$value];
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ private function includeProperties($includedData, $properties)
|
||||||
|
|
||||||
$values = $includedData[$propertyId];
|
$values = $includedData[$propertyId];
|
||||||
|
|
||||||
$result[$newKey] = $this->includeValues($values);
|
$result[$newKey] = $this->includeValues($propertyId, $values);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -284,15 +284,19 @@ private function includeProperties($includedData, $properties)
|
||||||
/**
|
/**
|
||||||
* Include specific values
|
* Include specific values
|
||||||
*/
|
*/
|
||||||
private function includeValues(array $values)
|
private function includeValues(string $propertyId, array $values)
|
||||||
{
|
{
|
||||||
$newValues = [];
|
$newValues = [];
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
|
if (in_array($key, $this->exclusions)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$newKey = $this->replaceValue($key, false, true);
|
$newKey = $this->replaceValue($key, false, true);
|
||||||
|
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$value = $this->includeValues($value);
|
$value = $this->includeValues($propertyId, $value);
|
||||||
} else {
|
} else {
|
||||||
$value = $this->replaceValue($value, false, true);
|
$value = $this->replaceValue($value, false, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
return [
|
return [
|
||||||
'P18',
|
'P18',
|
||||||
'P31',
|
'P31',
|
||||||
|
'P155',
|
||||||
|
'P156',
|
||||||
'P214',
|
'P214',
|
||||||
'P227',
|
'P227',
|
||||||
'P244',
|
'P244',
|
||||||
|
@ -22,6 +24,7 @@
|
||||||
'P674',
|
'P674',
|
||||||
'P691',
|
'P691',
|
||||||
'P905',
|
'P905',
|
||||||
|
'P910',
|
||||||
'P950',
|
'P950',
|
||||||
'P973',
|
'P973',
|
||||||
'P1015',
|
'P1015',
|
||||||
|
@ -31,6 +34,8 @@
|
||||||
'P1407',
|
'P1407',
|
||||||
'P1417',
|
'P1417',
|
||||||
'P1424',
|
'P1424',
|
||||||
|
'P1476',
|
||||||
|
'P1552',
|
||||||
'P1562',
|
'P1562',
|
||||||
'P1617',
|
'P1617',
|
||||||
'P1657',
|
'P1657',
|
||||||
|
@ -86,6 +91,7 @@
|
||||||
'P3212',
|
'P3212',
|
||||||
'P3216',
|
'P3216',
|
||||||
'P3222',
|
'P3222',
|
||||||
|
'P3302',
|
||||||
'P3306',
|
'P3306',
|
||||||
'P3402',
|
'P3402',
|
||||||
'P3417',
|
'P3417',
|
||||||
|
@ -150,6 +156,7 @@
|
||||||
'P6133',
|
'P6133',
|
||||||
'P6145',
|
'P6145',
|
||||||
'P6181',
|
'P6181',
|
||||||
|
'P6196',
|
||||||
'P6466',
|
'P6466',
|
||||||
'P6467',
|
'P6467',
|
||||||
'P6562',
|
'P6562',
|
||||||
|
@ -172,6 +179,7 @@
|
||||||
'P7502',
|
'P7502',
|
||||||
'P7573',
|
'P7573',
|
||||||
'P7777',
|
'P7777',
|
||||||
|
'P7818',
|
||||||
'P7822',
|
'P7822',
|
||||||
'P7970',
|
'P7970',
|
||||||
'P7975',
|
'P7975',
|
||||||
|
|
|
@ -1,46 +1,56 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'afterWorkBy' => [
|
'Inspiration' => [
|
||||||
|
'P144',
|
||||||
|
'P737',
|
||||||
|
'P941',
|
||||||
'P1877',
|
'P1877',
|
||||||
|
'P4969',
|
||||||
],
|
],
|
||||||
'staff' => [
|
'Équipe technique' => [
|
||||||
'P50',
|
'P50',
|
||||||
'P57',
|
'P57',
|
||||||
'P58',
|
'P58',
|
||||||
'P86',
|
'P86',
|
||||||
|
'P110',
|
||||||
'P162',
|
'P162',
|
||||||
'P170',
|
'P170',
|
||||||
'P175',
|
'P175',
|
||||||
'P178',
|
'P178',
|
||||||
|
'P287',
|
||||||
'P344',
|
'P344',
|
||||||
'P371',
|
'P371',
|
||||||
'P1040',
|
'P1040',
|
||||||
'P1431',
|
'P1431',
|
||||||
|
'P2184',
|
||||||
'P2515',
|
'P2515',
|
||||||
'P2554',
|
'P2554',
|
||||||
'P3092',
|
'P3092',
|
||||||
'P5028',
|
'P5028',
|
||||||
],
|
],
|
||||||
'productionCompanies' => [
|
'Production' => [
|
||||||
'P272',
|
'P272',
|
||||||
],
|
],
|
||||||
'genres' => [
|
'Publication' => [
|
||||||
'P136',
|
|
||||||
],
|
|
||||||
'subjects' => [
|
|
||||||
'P921',
|
|
||||||
],
|
|
||||||
'publishers' => [
|
|
||||||
'P123',
|
'P123',
|
||||||
],
|
],
|
||||||
'distribution' => [
|
'Diffusion' => [
|
||||||
|
'P449',
|
||||||
|
'P750',
|
||||||
|
'P747',
|
||||||
|
'P3301',
|
||||||
|
],
|
||||||
|
'Distribution' => [
|
||||||
'P161',
|
'P161',
|
||||||
|
'P725',
|
||||||
],
|
],
|
||||||
'sagas' => [
|
'Sagas' => [
|
||||||
'P179',
|
'P179',
|
||||||
|
'P1434',
|
||||||
|
'P8345',
|
||||||
],
|
],
|
||||||
'links' => [
|
'Liens' => [
|
||||||
'P856',
|
'P856',
|
||||||
'P345',
|
'P345',
|
||||||
'P1258',
|
'P1258',
|
||||||
|
@ -70,13 +80,53 @@
|
||||||
'P9751',
|
'P9751',
|
||||||
'P11460',
|
'P11460',
|
||||||
],
|
],
|
||||||
'locations' => [
|
'Genres' => [
|
||||||
|
'P136',
|
||||||
|
],
|
||||||
|
'Sujets abordés' => [
|
||||||
|
'P921',
|
||||||
|
],
|
||||||
|
'Lieux' => [
|
||||||
|
'P495',
|
||||||
'P840',
|
'P840',
|
||||||
'P915',
|
'P915',
|
||||||
],
|
],
|
||||||
'miscKeywords' => [
|
'Dates' => [
|
||||||
|
'P571',
|
||||||
|
'P577',
|
||||||
|
'P6949',
|
||||||
|
],
|
||||||
|
'Autres mots-clé' => [
|
||||||
'P180',
|
'P180',
|
||||||
'P8371',
|
'P8371',
|
||||||
'P8411',
|
'P8411',
|
||||||
],
|
],
|
||||||
|
'Langues' => [
|
||||||
|
'P364',
|
||||||
|
'P407',
|
||||||
|
],
|
||||||
|
'Distinctions' => [
|
||||||
|
'P166',
|
||||||
|
'P1411',
|
||||||
|
],
|
||||||
|
'Musique' => [
|
||||||
|
'P406',
|
||||||
|
'P942',
|
||||||
|
],
|
||||||
|
'Informations techniques' => [
|
||||||
|
'P408',
|
||||||
|
'P404',
|
||||||
|
'P479',
|
||||||
|
'P4151',
|
||||||
|
'P5196',
|
||||||
|
],
|
||||||
|
'Platformes' => [
|
||||||
|
'P306',
|
||||||
|
'P400',
|
||||||
|
'P8956',
|
||||||
|
],
|
||||||
|
'images' => [
|
||||||
|
'P154',
|
||||||
|
'P6802',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'links' => [
|
|
||||||
'P856' => [
|
'P856' => [
|
||||||
'template' => null,
|
'template' => null,
|
||||||
'title' => 'Site officiel',
|
'title' => 'Site officiel',
|
||||||
|
@ -114,5 +113,4 @@
|
||||||
'template' => 'https://app.plex.tv/desktop/#!/provider/tv.plex.provider.metadata/details?key=/library/metadata/%s',
|
'template' => 'https://app.plex.tv/desktop/#!/provider/tv.plex.provider.metadata/details?key=/library/metadata/%s',
|
||||||
'title' => 'Plex',
|
'title' => 'Plex',
|
||||||
],
|
],
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user