From 923505f146cc01ecb4960906a1d8ec38934e0342 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 21 Sep 2020 01:24:07 +0200 Subject: [PATCH] Add NodaUncertaintyHelper for guessing uncertainty of noda entries --- src/NodaUncertaintyHelper.php | 100 ++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/NodaUncertaintyHelper.php diff --git a/src/NodaUncertaintyHelper.php b/src/NodaUncertaintyHelper.php new file mode 100644 index 0000000..b9ee265 --- /dev/null +++ b/src/NodaUncertaintyHelper.php @@ -0,0 +1,100 @@ + + */ +declare(strict_types = 1); + +/** + * Contains static functions for getting IDs for noda entries by various means. + */ +final class NodaUncertaintyHelper { + + const TIME_UNCERTAINTY_PREFIXES = [ + "um ", + "wohl um ", + "circa ", + "ca. ", + "ca " + ]; + + const TIME_UNCERTAINTY_SUFFIXES = [ + "(?)", + "?", + ]; + + /** + * Substrings used to express uncertainty about the validity of a place name. + */ + const PLACE_UNCERTAINTY_PREFIXES = [ + "vlt. ", + "circa ", + "ca. ", + "ca ", + ]; + + const PLACE_UNCERTAINTY_SUFFIXES = [ + "(?)", + "?", + ]; + + /** + * Attempts guessing whether time is uncertain. + * + * @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 + } + } + + // 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 + } + } + + return true; // No uncertainty found + + } + + /** + * Attempts guessing whether place is uncertain. + * + * @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. + foreach (NodaUncertaintyHelper::PLACE_UNCERTAINTY_SUFFIXES as $prefix) { + if (\substr($ort_name, -1 * \strlen($prefix)) === $prefix) { + return false; // Uncertain + } + } + + return true; // Certain / no uncertainty found + + } + +}