1
0

Improving wikidata included properties and values

This commit is contained in:
Richard Dern 2024-04-24 23:29:33 +02:00
parent f7707dea23
commit 1e246cdd1a
4 changed files with 198 additions and 138 deletions

View File

@ -3,6 +3,7 @@
namespace App\Services\Wikidata;
use App\Models\WikidataProperty;
use Illuminate\Support\Str;
class WikidataExtractor
{
@ -115,7 +116,7 @@ private function browse(array $claims)
$newKey = $this->replaceValue($key, true, true);
$excluded[$newKey] = $claim;
} elseif ($isIncluded) {
$newKey = $this->replaceValue($key, true);
// $newKey = $this->replaceValue($key, true);
$included[$key] = $claim;
} elseif ($isUnused) {
$newKey = $this->replaceValue($key, true, true);
@ -202,8 +203,11 @@ private function parseSnak(array $data, bool $parentIncluded)
case 'monolingualtext':
$value = $value['text'];
break;
case 'globecoordinate':
// Leave it as is
break;
default:
return $data;
dd($data);
}
return $value;
@ -216,15 +220,11 @@ private function parseSnak(array $data, bool $parentIncluded)
*/
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;
$label = $value;
if (array_key_exists($value, $this->properties)) {
$label = $this->properties[$value];
$label = Str::ucfirst($this->properties[$value]);
} elseif (array_key_exists($value, $this->entities)) {
$label = $this->entities[$value];
}
@ -275,7 +275,7 @@ private function includeProperties($includedData, $properties)
$values = $includedData[$propertyId];
$result[$newKey] = $this->includeValues($values);
$result[$newKey] = $this->includeValues($propertyId, $values);
}
return $result;
@ -284,15 +284,19 @@ private function includeProperties($includedData, $properties)
/**
* Include specific values
*/
private function includeValues(array $values)
private function includeValues(string $propertyId, array $values)
{
$newValues = [];
foreach ($values as $key => $value) {
if (in_array($key, $this->exclusions)) {
continue;
}
$newKey = $this->replaceValue($key, false, true);
if (is_array($value)) {
$value = $this->includeValues($value);
$value = $this->includeValues($propertyId, $value);
} else {
$value = $this->replaceValue($value, false, true);
}

View File

@ -3,6 +3,8 @@
return [
'P18',
'P31',
'P155',
'P156',
'P214',
'P227',
'P244',
@ -22,6 +24,7 @@
'P674',
'P691',
'P905',
'P910',
'P950',
'P973',
'P1015',
@ -31,6 +34,8 @@
'P1407',
'P1417',
'P1424',
'P1476',
'P1552',
'P1562',
'P1617',
'P1657',
@ -86,6 +91,7 @@
'P3212',
'P3216',
'P3222',
'P3302',
'P3306',
'P3402',
'P3417',
@ -150,6 +156,7 @@
'P6133',
'P6145',
'P6181',
'P6196',
'P6466',
'P6467',
'P6562',
@ -172,6 +179,7 @@
'P7502',
'P7573',
'P7777',
'P7818',
'P7822',
'P7970',
'P7975',

View File

@ -1,46 +1,56 @@
<?php
return [
'afterWorkBy' => [
'Inspiration' => [
'P144',
'P737',
'P941',
'P1877',
'P4969',
],
'staff' => [
'Équipe technique' => [
'P50',
'P57',
'P58',
'P86',
'P110',
'P162',
'P170',
'P175',
'P178',
'P287',
'P344',
'P371',
'P1040',
'P1431',
'P2184',
'P2515',
'P2554',
'P3092',
'P5028',
],
'productionCompanies' => [
'Production' => [
'P272',
],
'genres' => [
'P136',
],
'subjects' => [
'P921',
],
'publishers' => [
'Publication' => [
'P123',
],
'distribution' => [
'Diffusion' => [
'P449',
'P750',
'P747',
'P3301',
],
'Distribution' => [
'P161',
'P725',
],
'sagas' => [
'Sagas' => [
'P179',
'P1434',
'P8345',
],
'links' => [
'Liens' => [
'P856',
'P345',
'P1258',
@ -70,13 +80,53 @@
'P9751',
'P11460',
],
'locations' => [
'Genres' => [
'P136',
],
'Sujets abordés' => [
'P921',
],
'Lieux' => [
'P495',
'P840',
'P915',
],
'miscKeywords' => [
'Dates' => [
'P571',
'P577',
'P6949',
],
'Autres mots-clé' => [
'P180',
'P8371',
'P8411',
],
'Langues' => [
'P364',
'P407',
],
'Distinctions' => [
'P166',
'P1411',
],
'Musique' => [
'P406',
'P942',
],
'Informations techniques' => [
'P408',
'P404',
'P479',
'P4151',
'P5196',
],
'Platformes' => [
'P306',
'P400',
'P8956',
],
'images' => [
'P154',
'P6802',
],
];

View File

@ -1,118 +1,116 @@
<?php
return [
'links' => [
'P856' => [
'template' => null,
'title' => 'Site officiel',
],
'P345' => [
'template' => 'https://www.imdb.com/title/%s/',
'title' => 'IMDB',
],
'P1258' => [
'template' => 'https://www.rottentomatoes.com/%s',
'title' => 'Rotten Tomatoes',
],
'P1265' => [
'template' => 'https://www.allocine.fr/film/fichefilm_gen_cfilm=%s.html',
'title' => 'AlloCiné',
],
'P1267' => [
'template' => 'https://www.allocine.fr/series/ficheserie_gen_cserie=%s.html',
'title' => 'AlloCiné',
],
'P1651' => [
'template' => 'https://www.youtube.com/watch?v=%s',
'title' => 'YouTube',
],
'P1712' => [
'template' => 'https://www.metacritic.com/%s',
'title' => 'Metacritic',
],
'P1733' => [
'template' => 'https://store.steampowered.com/app/%s/',
'title' => 'Steam',
],
'P1874' => [
'template' => 'https://www.netflix.com/title/%s',
'title' => 'Netflix',
],
'P2002' => [
'template' => 'https://twitter.com/%s',
'title' => 'X',
],
'P2003' => [
'template' => 'https://www.instagram.com/%s',
'title' => 'Instagram',
],
'P2013' => [
'template' => 'https://www.facebook.com/%s',
'title' => 'facebook',
],
'P2397' => [
'template' => 'https://www.youtube.com/channel/%s',
'title' => 'Chaîne YouTube',
],
'P3984' => [
'template' => 'https://www.reddit.com/r/%s/',
'title' => 'Reddit',
],
'P4013' => [
'template' => 'https://giphy.com/%s',
'title' => 'Giphy',
],
'P4073' => [
'template' => 'https://community.fandom.com/wiki/w:c:%s',
'title' => 'Fandom',
],
'P4477' => [
'template' => 'https://www.humblebundle.com/store/%s',
'title' => 'Humble Store',
],
'P4947' => [
'template' => 'https://www.themoviedb.org/movie/%s',
'title' => 'TMDB',
],
'P4983' => [
'template' => 'https://www.themoviedb.org/tv/%s',
'title' => 'TMBD',
],
'P5749' => [
'template' => 'https://www.amazon.com/dp/%s',
'title' => 'Amazon',
],
'P6262' => [
'template' => 'https://community.fandom.com/wiki/w:c:%s',
'title' => 'Fandom',
],
'P6398' => [
'template' => 'https://itunes.apple.com/us/movie/id%s',
'title' => 'iTunes',
],
'P7595' => [
'template' => 'https://www.disneyplus.com/movies/wd/%s',
'title' => 'Disney+',
],
'P7596' => [
'template' => 'https://www.disneyplus.com/series/wp/%s',
'title' => 'Disney+',
],
'P8055' => [
'template' => 'https://www.amazon.com/gp/video/detail/%s',
'title' => 'Amazon Prime',
],
'P9586' => [
'template' => 'https://tv.apple.com/movie/%s',
'title' => 'Apple TV',
],
'P9751' => [
'template' => 'https://tv.apple.com/show/%s',
'title' => 'Apple TV',
],
'P11460' => [
'template' => 'https://app.plex.tv/desktop/#!/provider/tv.plex.provider.metadata/details?key=/library/metadata/%s',
'title' => 'Plex',
],
'P856' => [
'template' => null,
'title' => 'Site officiel',
],
'P345' => [
'template' => 'https://www.imdb.com/title/%s/',
'title' => 'IMDB',
],
'P1258' => [
'template' => 'https://www.rottentomatoes.com/%s',
'title' => 'Rotten Tomatoes',
],
'P1265' => [
'template' => 'https://www.allocine.fr/film/fichefilm_gen_cfilm=%s.html',
'title' => 'AlloCiné',
],
'P1267' => [
'template' => 'https://www.allocine.fr/series/ficheserie_gen_cserie=%s.html',
'title' => 'AlloCiné',
],
'P1651' => [
'template' => 'https://www.youtube.com/watch?v=%s',
'title' => 'YouTube',
],
'P1712' => [
'template' => 'https://www.metacritic.com/%s',
'title' => 'Metacritic',
],
'P1733' => [
'template' => 'https://store.steampowered.com/app/%s/',
'title' => 'Steam',
],
'P1874' => [
'template' => 'https://www.netflix.com/title/%s',
'title' => 'Netflix',
],
'P2002' => [
'template' => 'https://twitter.com/%s',
'title' => 'X',
],
'P2003' => [
'template' => 'https://www.instagram.com/%s',
'title' => 'Instagram',
],
'P2013' => [
'template' => 'https://www.facebook.com/%s',
'title' => 'facebook',
],
'P2397' => [
'template' => 'https://www.youtube.com/channel/%s',
'title' => 'Chaîne YouTube',
],
'P3984' => [
'template' => 'https://www.reddit.com/r/%s/',
'title' => 'Reddit',
],
'P4013' => [
'template' => 'https://giphy.com/%s',
'title' => 'Giphy',
],
'P4073' => [
'template' => 'https://community.fandom.com/wiki/w:c:%s',
'title' => 'Fandom',
],
'P4477' => [
'template' => 'https://www.humblebundle.com/store/%s',
'title' => 'Humble Store',
],
'P4947' => [
'template' => 'https://www.themoviedb.org/movie/%s',
'title' => 'TMDB',
],
'P4983' => [
'template' => 'https://www.themoviedb.org/tv/%s',
'title' => 'TMBD',
],
'P5749' => [
'template' => 'https://www.amazon.com/dp/%s',
'title' => 'Amazon',
],
'P6262' => [
'template' => 'https://community.fandom.com/wiki/w:c:%s',
'title' => 'Fandom',
],
'P6398' => [
'template' => 'https://itunes.apple.com/us/movie/id%s',
'title' => 'iTunes',
],
'P7595' => [
'template' => 'https://www.disneyplus.com/movies/wd/%s',
'title' => 'Disney+',
],
'P7596' => [
'template' => 'https://www.disneyplus.com/series/wp/%s',
'title' => 'Disney+',
],
'P8055' => [
'template' => 'https://www.amazon.com/gp/video/detail/%s',
'title' => 'Amazon Prime',
],
'P9586' => [
'template' => 'https://tv.apple.com/movie/%s',
'title' => 'Apple TV',
],
'P9751' => [
'template' => 'https://tv.apple.com/show/%s',
'title' => 'Apple TV',
],
'P11460' => [
'template' => 'https://app.plex.tv/desktop/#!/provider/tv.plex.provider.metadata/details?key=/library/metadata/%s',
'title' => 'Plex',
],
];