Ran phpcbf over code

This commit is contained in:
Joshua Ramon Enslin 2024-07-08 00:48:50 +02:00
parent 205e77da0e
commit 27528c9cf7
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
12 changed files with 190 additions and 210 deletions

View File

@ -10,7 +10,6 @@ declare(strict_types = 1);
* Abstract class to be inherited by classes for writing consolidated vocabulary names. * Abstract class to be inherited by classes for writing consolidated vocabulary names.
*/ */
abstract class NodaConsolidatedNamesAbstract { abstract class NodaConsolidatedNamesAbstract {
/** /**
* This function sanitizes a string. * This function sanitizes a string.
* *

View File

@ -120,5 +120,4 @@ final class NodaConsolidatedNamesForPersinst extends NodaConsolidatedNamesAbstra
return \trim($name, " ;.\t" . PHP_EOL); return \trim($name, " ;.\t" . PHP_EOL);
} }
} }

View File

@ -105,8 +105,7 @@ final class NodaConsolidatedNamesForPlaces extends NodaConsolidatedNamesAbstract
// Skip entries like "Vaci utca 12 Budapest, Vaci utca" // Skip entries like "Vaci utca 12 Budapest, Vaci utca"
$indicatorTrimmed = trim($indicator); $indicatorTrimmed = trim($indicator);
if ( if ((str_ends_with($parts[0], $indicatorTrimmed) && str_contains($parts[1], $indicatorTrimmed))
(str_ends_with($parts[0], $indicatorTrimmed) && str_contains($parts[1], $indicatorTrimmed))
|| (str_ends_with($parts[1], $indicatorTrimmed) && str_contains($parts[0], $indicatorTrimmed)) || (str_ends_with($parts[1], $indicatorTrimmed) && str_contains($parts[0], $indicatorTrimmed))
) { ) {
return $name; return $name;
@ -133,10 +132,8 @@ final class NodaConsolidatedNamesForPlaces extends NodaConsolidatedNamesAbstract
} }
} }
return $name; return $name;
} }
@ -334,7 +331,6 @@ final class NodaConsolidatedNamesForPlaces extends NodaConsolidatedNamesAbstract
} }
/** /**
* Cleans and consolidates name parts appearing regularly in Ukrainian place names. * Cleans and consolidates name parts appearing regularly in Ukrainian place names.
* *
@ -427,15 +423,12 @@ final class NodaConsolidatedNamesForPlaces extends NodaConsolidatedNamesAbstract
// If one of the parts is a blacklisted term or a cardinal directions, skip this // If one of the parts is a blacklisted term or a cardinal directions, skip this
if ( if ((in_array($parts[0], self::_COUNTRY_REWRITE_BLACKLISTED_TERMS, true)
(in_array($parts[0], self::_COUNTRY_REWRITE_BLACKLISTED_TERMS, true) || in_array($parts[0], $cardinal_directions, true)
|| in_array($parts[0], $cardinal_directions, true) || in_array(strtolower($parts[0]), $cardinal_directions, true))
|| in_array(strtolower($parts[0]), $cardinal_directions, true)
)
|| (in_array($parts[1], self::_COUNTRY_REWRITE_BLACKLISTED_TERMS, true) || (in_array($parts[1], self::_COUNTRY_REWRITE_BLACKLISTED_TERMS, true)
|| in_array($parts[1], $cardinal_directions, true) || in_array($parts[1], $cardinal_directions, true)
|| in_array(strtolower($parts[1]), $cardinal_directions, true) || in_array(strtolower($parts[1]), $cardinal_directions, true))
)
) { ) {
return $name; return $name;
} }

View File

@ -10,7 +10,6 @@ declare(strict_types = 1);
* contains a string. * contains a string.
*/ */
final class NodaDistinctlyTypedStrings { final class NodaDistinctlyTypedStrings {
/** /**
* Checks the vocabulary database whether it contains a given string. * Checks the vocabulary database whether it contains a given string.
* *
@ -40,5 +39,4 @@ final class NodaDistinctlyTypedStrings {
return $cur[0]; return $cur[0];
} }
} }

View File

@ -11,7 +11,7 @@ declare(strict_types = 1);
*/ */
final class NodaSplitTime { final class NodaSplitTime {
const DEFAULT_DATE = '0001-01-01'; public const DEFAULT_DATE = '0001-01-01';
public readonly string $start_year; public readonly string $start_year;
public readonly string $end_year; public readonly string $end_year;
@ -40,11 +40,13 @@ final class NodaSplitTime {
$start_date = $end_date = $year . '-' . $month . '-' . $day; $start_date = $end_date = $year . '-' . $month . '-' . $day;
if ($before_after_indicator === NodaTimeBeforeAfterIndicator::before if ($before_after_indicator === NodaTimeBeforeAfterIndicator::before
|| $before_after_indicator === NodaTimeBeforeAfterIndicator::until) { || $before_after_indicator === NodaTimeBeforeAfterIndicator::until
) {
$start_year = $start_date = '?'; $start_year = $start_date = '?';
} }
if ($before_after_indicator === NodaTimeBeforeAfterIndicator::after if ($before_after_indicator === NodaTimeBeforeAfterIndicator::after
|| $before_after_indicator === NodaTimeBeforeAfterIndicator::since) { || $before_after_indicator === NodaTimeBeforeAfterIndicator::since
) {
$end_year = $end_date = '?'; $end_year = $end_date = '?';
} }
@ -94,7 +96,6 @@ final class NodaSplitTime {
throw new MDgenericInvalidInputsException("Times with no certain end need to have a question mark (?) entered as a end date"); throw new MDgenericInvalidInputsException("Times with no certain end need to have a question mark (?) entered as a end date");
} }
} }
/** /**
@ -272,7 +273,6 @@ final class NodaSplitTime {
return ""; return "";
} }
/** /**
@ -330,7 +330,6 @@ final class NodaSplitTime {
$this->end_date = '9999-12-31'; $this->end_date = '9999-12-31';
} }
if (!isset($this->start_date) && false !== $start_date) { if (!isset($this->start_date) && false !== $start_date) {
$this->start_date = date("Y-m-d", MD_STD::strtotime($start_date)); $this->start_date = date("Y-m-d", MD_STD::strtotime($start_date));
} }
@ -361,7 +360,5 @@ final class NodaSplitTime {
} }
} }
} }
} }

View File

@ -888,11 +888,10 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum); $datum = self::clean_input($datum);
// TODO: Check if this is duplicate // TODO: Check if this is duplicate
// 17. Jahrhundert // 17. Jahrhundert
if (\preg_match("/^[0-9]{2}(\.|)" . self::REGEX_CENTURIES ."$/", $datum)) { if (\preg_match("/^[0-9]{2}(\.|)" . self::REGEX_CENTURIES . "$/", $datum)) {
if ($centuryNo = \intval(\substr($datum, 0, 2))) { if ($centuryNo = \intval(\substr($datum, 0, 2))) {
$centuryNo--; $centuryNo--;
return new NodaSplitTime((string)$centuryNo . "01", \strval($centuryNo + 1) . "00"); return new NodaSplitTime((string)$centuryNo . "01", \strval($centuryNo + 1) . "00");

View File

@ -94,9 +94,9 @@ final class NodaUncertaintyHelper {
"Без датування", // No dating "Без датування", // No dating
"б.р.", // No dating "б.р.", // No dating
"б.д.", // No dating "б.д.", // No dating
]; ];
const TIME_UNCERTAINTY_PREFIXES = [ const TIME_UNCERTAINTY_PREFIXES = [
"c. ", "c. ",
"ca ", "ca ",
"ca. ", "ca. ",
@ -130,9 +130,9 @@ final class NodaUncertaintyHelper {
"майже", // UK: Almost / nearly / about "майже", // UK: Almost / nearly / about
"орієнтовно", // UK: approximately "орієнтовно", // UK: approximately
"Прибл.", // UK: approximately "Прибл.", // UK: approximately
]; ];
const TIME_UNCERTAINTY_SUFFIXES = [ const TIME_UNCERTAINTY_SUFFIXES = [
"(?)", "(?)",
"?", "?",
" (ca.)", " (ca.)",
@ -145,11 +145,11 @@ final class NodaUncertaintyHelper {
", um", ", um",
" (um)", " (um)",
" (ок.)", " (ок.)",
]; ];
/** /**
* Substrings used to express uncertainty about the validity of a place name. * Substrings used to express uncertainty about the validity of a place name.
*/ */
const PLACE_INDICATORS_DISALLOWED = [ const PLACE_INDICATORS_DISALLOWED = [
"Unbekannt", "Unbekannt",
"unbekannt", "unbekannt",
@ -173,9 +173,9 @@ final class NodaUncertaintyHelper {
"не вказано", // No place "не вказано", // No place
"не вказане", // No place "не вказане", // No place
"невідоме", // No place "невідоме", // No place
]; ];
const PLACE_UNCERTAINTY_PREFIXES = [ const PLACE_UNCERTAINTY_PREFIXES = [
"ca ", "ca ",
"Ca ", "Ca ",
"ca. ", "ca. ",
@ -210,9 +210,9 @@ final class NodaUncertaintyHelper {
"Wahrscheinlich ", "Wahrscheinlich ",
"можливо", "можливо",
"?", "?",
]; ];
const PLACE_UNCERTAINTY_SUFFIXES = [ const PLACE_UNCERTAINTY_SUFFIXES = [
"(?)", "(?)",
"(vermutl.)", "(vermutl.)",
"[vermutl.]", "[vermutl.]",
@ -221,206 +221,206 @@ final class NodaUncertaintyHelper {
"(wohl)", "(wohl)",
"[wohl]", "[wohl]",
"?", "?",
]; ];
/** /**
* Trims common characters and charater marks. * Trims common characters and charater marks.
* *
* @param string $input Input text. * @param string $input Input text.
* *
* @return string * @return string
*/ */
public static function trim(string $input):string { public static function trim(string $input):string {
$input = \trim($input, ", \t\n\r\n;-:"); $input = \trim($input, ", \t\n\r\n;-:");
return $input; return $input;
}
/**
* Removes uncertainty indicators from an time name.
*
* @param string $name Input string.
*
* @return string
*/
public static function cleanUncertaintyIndicatorsTime(string $name):string {
$name = self::trim($name);
if (\in_array($name, self::TIME_INDICATORS_DISALLOWED, true)) {
return "";
} }
// Remove uncertainty prefixes /**
foreach (NodaUncertaintyHelper::TIME_UNCERTAINTY_PREFIXES as $prefix) { * Removes uncertainty indicators from an time name.
if (\substr($name, 0, \strlen($prefix)) === "$prefix") { *
$name = substr($name, \strlen($prefix)); * @param string $name Input string.
*
* @return string
*/
public static function cleanUncertaintyIndicatorsTime(string $name):string {
$name = self::trim($name);
if (\in_array($name, self::TIME_INDICATORS_DISALLOWED, true)) {
return "";
} }
}
// Remove uncertainty sufixes // Remove uncertainty prefixes
foreach (NodaUncertaintyHelper::TIME_UNCERTAINTY_SUFFIXES as $suffix) { foreach (NodaUncertaintyHelper::TIME_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($name, \strlen($suffix) * -1) === "$suffix") { if (\substr($name, 0, \strlen($prefix)) === "$prefix") {
$name = \substr($name, 0, \strlen($suffix) * -1); $name = substr($name, \strlen($prefix));
}
} }
}
return self::trim($name); // Remove uncertainty sufixes
foreach (NodaUncertaintyHelper::TIME_UNCERTAINTY_SUFFIXES as $suffix) {
} if (\substr($name, \strlen($suffix) * -1) === "$suffix") {
$name = \substr($name, 0, \strlen($suffix) * -1);
/** }
* Attempts guessing whether time is uncertain. Returns true if the name
* indicates certainty, false if it indicates uncertainty.
*
* @param string $zeit_name Time name.
*
* @return boolean
*/
public static function guessTimeCertainty(string $zeit_name):bool {
$zeit_name = \strtolower($zeit_name);
// Attempt to guess uncertainty based on prefixes.
foreach (self::TIME_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($zeit_name, 0, \strlen($prefix)) === $prefix) {
return false; // Uncertainty found
} }
return self::trim($name);
} }
// Attempt to guess uncertainty based on prefixes. /**
foreach (self::TIME_UNCERTAINTY_SUFFIXES as $prefix) { * Attempts guessing whether time is uncertain. Returns true if the name
if (\substr($zeit_name, -1 * \strlen($prefix)) === $prefix) { * indicates certainty, false if it indicates uncertainty.
return false; // Uncertainty found *
* @param string $zeit_name Time name.
*
* @return boolean
*/
public static function guessTimeCertainty(string $zeit_name):bool {
$zeit_name = \strtolower($zeit_name);
// Attempt to guess uncertainty based on prefixes.
foreach (self::TIME_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($zeit_name, 0, \strlen($prefix)) === $prefix) {
return false; // Uncertainty found
}
} }
}
return true; // No uncertainty found // Attempt to guess uncertainty based on prefixes.
foreach (self::TIME_UNCERTAINTY_SUFFIXES as $prefix) {
} if (\substr($zeit_name, -1 * \strlen($prefix)) === $prefix) {
return false; // Uncertainty found
/** }
* Removes uncertainty indicators from an place name.
*
* @param string $ort_name Input string.
*
* @return string
*/
public static function cleanUncertaintyIndicatorsPlace(string $ort_name):string {
$ort_name = self::trim($ort_name);
if (\in_array($ort_name, self::PLACE_INDICATORS_DISALLOWED, true)) {
return "";
}
// Remove uncertainty prefixes
foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($ort_name, 0, \strlen($prefix)) === "$prefix") {
$ort_name = substr($ort_name, \strlen($prefix));
} }
return true; // No uncertainty found
} }
// Remove uncertainty sufixes /**
foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_SUFFIXES as $suffix) { * Removes uncertainty indicators from an place name.
if (\substr($ort_name, \strlen($suffix) * -1) === "$suffix") { *
$ort_name = \substr($ort_name, 0, \strlen($suffix) * -1); * @param string $ort_name Input string.
*
* @return string
*/
public static function cleanUncertaintyIndicatorsPlace(string $ort_name):string {
$ort_name = self::trim($ort_name);
if (\in_array($ort_name, self::PLACE_INDICATORS_DISALLOWED, true)) {
return "";
} }
}
return self::trim($ort_name); // Remove uncertainty prefixes
foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_PREFIXES as $prefix) {
} if (\substr($ort_name, 0, \strlen($prefix)) === "$prefix") {
$ort_name = substr($ort_name, \strlen($prefix));
/** }
* Attempts guessing whether place is uncertain. Returns true if the name
* indicates certainty, false if it indicates uncertainty.
*
* @param string $ort_name Place name.
*
* @return boolean
*/
public static function guessPlaceCertainty(string $ort_name):bool {
$ort_name = \strtolower($ort_name);
// Attempt to guess uncertainty based on prefixes.
foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($ort_name, 0, \strlen($prefix)) === $prefix) {
return false; // Uncertain
} }
}
// Attempt to guess uncertainty based on prefixes. // Remove uncertainty sufixes
foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_SUFFIXES as $prefix) { foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_SUFFIXES as $suffix) {
if (\substr($ort_name, -1 * \strlen($prefix)) === $prefix) { if (\substr($ort_name, \strlen($suffix) * -1) === "$suffix") {
return false; // Uncertain $ort_name = \substr($ort_name, 0, \strlen($suffix) * -1);
}
} }
return self::trim($ort_name);
} }
return true; // Certain / no uncertainty found /**
* Attempts guessing whether place is uncertain. Returns true if the name
* indicates certainty, false if it indicates uncertainty.
*
* @param string $ort_name Place name.
*
* @return boolean
*/
public static function guessPlaceCertainty(string $ort_name):bool {
} $ort_name = \strtolower($ort_name);
/** // Attempt to guess uncertainty based on prefixes.
* Removes uncertainty indicators from an actor name. foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_PREFIXES as $prefix) {
* if (\substr($ort_name, 0, \strlen($prefix)) === $prefix) {
* @param string $value Input string. return false; // Uncertain
* }
* @return string
*/
public static function cleanUncertaintyIndicatorsPersinst(string $value):string {
$value = self::trim($value);
if (\in_array(trim($value, ";. "), self::PERSINST_INDICATORS_DISALLOWED, true)) {
return "";
}
foreach (self::PERSINST_UNCERTAINTY_PREFIXES as $toRemove) {
if (\mb_substr($value, 0, \mb_strlen($toRemove)) === $toRemove) {
$value = substr($value, \mb_strlen($toRemove));
} }
}
foreach (self::PLACE_UNCERTAINTY_SUFFIXES as $suffix) { // Attempt to guess uncertainty based on prefixes.
if (\mb_substr($value, \mb_strlen($suffix) * -1) === "$suffix") { foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_SUFFIXES as $prefix) {
$value = \mb_substr($value, 0, \mb_strlen($suffix) * -1); if (\substr($ort_name, -1 * \strlen($prefix)) === $prefix) {
return false; // Uncertain
}
} }
return true; // Certain / no uncertainty found
} }
return self::trim($value); /**
* Removes uncertainty indicators from an actor name.
*
* @param string $value Input string.
*
* @return string
*/
public static function cleanUncertaintyIndicatorsPersinst(string $value):string {
} $value = self::trim($value);
/** if (\in_array(trim($value, ";. "), self::PERSINST_INDICATORS_DISALLOWED, true)) {
* Attempts guessing whether persinst is uncertain. Returns true if the name return "";
* indicates certainty, false if it indicates uncertainty.
*
* @param string $name Persinst name.
*
* @return boolean
*/
public static function guessPersinstCertainty(string $name):bool {
$name = \trim(\strtolower($name));
// Attempt to guess uncertainty based on prefixes.
foreach (NodaUncertaintyHelper::PERSINST_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($name, 0, \strlen($prefix)) === $prefix) {
return false; // Uncertain
} }
}
// Attempt to guess uncertainty based on prefixes. foreach (self::PERSINST_UNCERTAINTY_PREFIXES as $toRemove) {
foreach (NodaUncertaintyHelper::PERSINST_UNCERTAINTY_SUFFIXES as $prefix) { if (\mb_substr($value, 0, \mb_strlen($toRemove)) === $toRemove) {
if (\substr($name, -1 * \strlen($prefix)) === $prefix) { $value = substr($value, \mb_strlen($toRemove));
return false; // Uncertain }
} }
foreach (self::PLACE_UNCERTAINTY_SUFFIXES as $suffix) {
if (\mb_substr($value, \mb_strlen($suffix) * -1) === "$suffix") {
$value = \mb_substr($value, 0, \mb_strlen($suffix) * -1);
}
}
return self::trim($value);
} }
return true; // Certain / no uncertainty found /**
* Attempts guessing whether persinst is uncertain. Returns true if the name
* indicates certainty, false if it indicates uncertainty.
*
* @param string $name Persinst name.
*
* @return boolean
*/
public static function guessPersinstCertainty(string $name):bool {
} $name = \trim(\strtolower($name));
// Attempt to guess uncertainty based on prefixes.
foreach (NodaUncertaintyHelper::PERSINST_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($name, 0, \strlen($prefix)) === $prefix) {
return false; // Uncertain
}
}
// Attempt to guess uncertainty based on prefixes.
foreach (NodaUncertaintyHelper::PERSINST_UNCERTAINTY_SUFFIXES as $prefix) {
if (\substr($name, -1 * \strlen($prefix)) === $prefix) {
return false; // Uncertain
}
}
return true; // Certain / no uncertainty found
}
} }

View File

@ -19,9 +19,9 @@ final class NodaValidationHelper {
* made. * made.
* *
* @param string $description Input descrition. * @param string $description Input descrition.
* @param string $name Names of the actor. Optional. Setting this enables * @param string $name Names of the actor. Optional. Setting this enables
* checks e.g. to prevent duplicating the actor name * checks e.g. to prevent duplicating the actor name
* as a description. * as a description.
* *
* @return void * @return void
*/ */

View File

@ -56,7 +56,6 @@ final class NodaConsolidatedNamesForPlacesTest extends TestCase {
self::assertEquals("Deák Ferenc utca 16-18. (Budapest, 5. kerület)", NodaConsolidatedNamesForPlaces::consolidate_name("hu", "Deák Ferenc utca 16-18. Budapest, V.")); self::assertEquals("Deák Ferenc utca 16-18. (Budapest, 5. kerület)", NodaConsolidatedNamesForPlaces::consolidate_name("hu", "Deák Ferenc utca 16-18. Budapest, V."));
self::assertEquals("Deák Ferenc utca 16-18. Budapest, V. abc", NodaConsolidatedNamesForPlaces::consolidate_name("hu", "Deák Ferenc utca 16-18. Budapest, V. abc")); self::assertEquals("Deák Ferenc utca 16-18. Budapest, V. abc", NodaConsolidatedNamesForPlaces::consolidate_name("hu", "Deák Ferenc utca 16-18. Budapest, V. abc"));
// Rewriting country names in brackets // Rewriting country names in brackets
self::assertEquals("Köln (Deutschland)", NodaConsolidatedNamesForPlaces::consolidate_name("de", "Deutschland-Köln")); self::assertEquals("Köln (Deutschland)", NodaConsolidatedNamesForPlaces::consolidate_name("de", "Deutschland-Köln"));
self::assertEquals("Köln (Deutschland)", NodaConsolidatedNamesForPlaces::consolidate_name("de", "Deutschland, Köln")); self::assertEquals("Köln (Deutschland)", NodaConsolidatedNamesForPlaces::consolidate_name("de", "Deutschland, Köln"));

View File

@ -37,7 +37,6 @@ final class NodaTimeSplitterTest extends TestCase {
self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("02.1.25 v. Chr"); $output = NodaTimeSplitter::attempt_splitting("02.1.25 v. Chr");
self::assertNotEmpty($output); self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [ self::assertEquals($output->toOldFormat(), [

View File

@ -12,8 +12,6 @@ use PHPUnit\Framework\Attributes\Small;
/** /**
* This script contains tests for the validation of single field contents. * This script contains tests for the validation of single field contents.
*
* @covers \NodaValidationHelper
*/ */
#[small] #[small]
#[CoversClass(\NodaValidationHelper::class)] #[CoversClass(\NodaValidationHelper::class)]

View File

@ -20,6 +20,5 @@ declare(strict_types = 1);
} }
} }
}); });