Improve trimming inputs when cleaning certainty indicators

This commit is contained in:
Joshua Ramon Enslin 2020-10-04 22:52:15 +02:00 committed by Stefan Rohde-Enslin
parent 1f4d692fb5
commit d0fe1e89ed

View File

@ -68,6 +68,20 @@ final class NodaUncertaintyHelper {
"?",
];
/**
* Trims common characters and charater marks.
*
* @param string $input Input text.
*
* @return string
*/
public static function trim(string $input):string {
$input = \trim($input, ", \t\n\r\n;-:");
return $input;
}
/**
* Removes uncertainty indicators from an time name.
*
@ -77,6 +91,8 @@ final class NodaUncertaintyHelper {
*/
public static function cleanUncertaintyIndicatorsTime(string $name):string {
$name = self::trim($name);
if (\in_array($name, self::TIME_INDICATORS_DISALLOWED, true)) {
return "";
}
@ -84,18 +100,18 @@ final class NodaUncertaintyHelper {
// Remove uncertainty prefixes
foreach (NodaUncertaintyHelper::TIME_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($name, 0, \strlen($prefix)) === "$prefix") {
$name = trim(substr($name, \strlen($prefix)));
$name = substr($name, \strlen($prefix));
}
}
// Remove uncertainty sufixes
foreach (NodaUncertaintyHelper::TIME_UNCERTAINTY_SUFFIXES as $suffix) {
if (\substr($name, \strlen($suffix) * -1) === "$suffix") {
$name = \trim(\substr($name, 0, \strlen($suffix) * -1));
$name = \substr($name, 0, \strlen($suffix) * -1);
}
}
return \trim($name);
return self::trim($name);
}
@ -137,7 +153,7 @@ final class NodaUncertaintyHelper {
*/
public static function cleanUncertaintyIndicatorsPlace(string $ort_name):string {
$ort_name = \trim($ort_name);
$ort_name = self::trim($ort_name);
if (\in_array($ort_name, self::PLACE_INDICATORS_DISALLOWED, true)) {
return "";
@ -146,18 +162,18 @@ final class NodaUncertaintyHelper {
// Remove uncertainty prefixes
foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_PREFIXES as $prefix) {
if (\substr($ort_name, 0, \strlen($prefix)) === "$prefix") {
$ort_name = trim(substr($ort_name, \strlen($prefix)));
$ort_name = substr($ort_name, \strlen($prefix));
}
}
// Remove uncertainty sufixes
foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_SUFFIXES as $suffix) {
if (\substr($ort_name, \strlen($suffix) * -1) === "$suffix") {
$ort_name = \trim(\substr($ort_name, 0, \strlen($suffix) * -1));
$ort_name = \substr($ort_name, 0, \strlen($suffix) * -1);
}
}
return \trim($ort_name);
return self::trim($ort_name);
}
@ -199,7 +215,7 @@ final class NodaUncertaintyHelper {
*/
public static function cleanUncertaintyIndicatorsPersinst(string $value):string {
$value = \trim($value);
$value = self::trim($value);
if (\in_array($value, self::PERSINST_INDICATORS_DISALLOWED, true)) {
return "";
@ -217,7 +233,7 @@ final class NodaUncertaintyHelper {
}
}
return \trim($value);
return self::trim($value);
}