Allow name flattening rules where multiple old values map to the same new ID

this allows more compaction in certain cases, such as tallgrass recently.
instead of blacklisting any mapping which reuses the same flattened infix, we select the flatten property which produces the smallest number of distinct rules, which produces the most compact schema possible.
this change also permits potentially flattening other types of properties such as for corals (live/dead and type), although only one may be selected at a time.
This commit is contained in:
Dylan K. Taylor 2024-08-05 22:33:30 +01:00
parent 54e7749c0b
commit bdb5845cec
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -42,6 +42,7 @@ use function array_key_last;
use function array_keys;
use function array_map;
use function array_shift;
use function array_unique;
use function array_values;
use function count;
use function dirname;
@ -423,6 +424,10 @@ function processRemappedStates(array $upgradeTable) : array{
$filter = $pair->old->getStates();
foreach($unchangedStatesByNewName[$pair->new->getName()] as $unchangedPropertyName){
if($unchangedPropertyName === $propertyName){
$notFlattenedProperties[$propertyName] = true;
continue 2;
}
unset($filter[$unchangedPropertyName]);
}
unset($filter[$propertyName]);
@ -436,26 +441,31 @@ function processRemappedStates(array $upgradeTable) : array{
$notFlattenedProperties[$propertyName] = true;
continue;
}
foreach(Utils::stringifyKeys($valuesToIds) as $otherRawValue => $otherNewId){
if($otherRawValue === $rawValue){
continue;
}
if($otherNewId === $pair->new->getName()){
//this old value maps to the same new ID as another old value - bad candidate for flattening
$notFlattenedProperties[$propertyName] = true;
continue 2;
}
}
}
$candidateFlattenedValues[$propertyName][$rawFilter][$rawValue] = $pair->new->getName();
}
}
foreach(Utils::stringifyKeys($candidateFlattenedValues) as $propertyName => $filters){
foreach($filters as $valuesToIds){
if(count(array_unique($valuesToIds)) === 1){
//this property doesn't influence the new ID
$notFlattenedProperties[$propertyName] = true;
continue 2;
}
}
}
foreach(Utils::stringifyKeys($notFlattenedProperties) as $propertyName => $_){
unset($candidateFlattenedValues[$propertyName]);
}
$flattenedProperties = buildFlattenPropertyRules($candidateFlattenedValues);
$flattenProperty = array_key_first($flattenedProperties);
//Properties with fewer rules take up less space for the same result
foreach(Utils::stringifyKeys($flattenedProperties) as $propertyName => $rules){
if(count($rules) < count($flattenedProperties[$flattenProperty])){
$flattenProperty = $propertyName;
}
}
$list = [];