MDNodaHelpers/src/NodaUncertaintyHelper.php

101 lines
2.5 KiB
PHP
Raw Normal View History

<?PHP
/**
* Contains class NodaUncertaintyHelper.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
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
}
}