diff --git a/exceptions/MDImporterMissingConcordance.php b/exceptions/MDImporterMissingConcordance.php new file mode 100644 index 0000000..ce24a94 --- /dev/null +++ b/exceptions/MDImporterMissingConcordance.php @@ -0,0 +1,18 @@ + + */ +declare(strict_types = 1); + +/** + * Describes a concordance list for importer concordance lists. + */ +interface MDImporterConcordanceListInterface { + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return mixed + */ + public static function getConcordanceTarget(string $input); +} diff --git a/src/MDConcActor.php b/src/MDConcActor.php index 8e46ed4..be69bc5 100644 --- a/src/MDConcActor.php +++ b/src/MDConcActor.php @@ -9,7 +9,7 @@ declare(strict_types = 1); /** * Provides a list for finding the respective event type for a given actor role. */ -final class MDConcActor { +final class MDConcActor implements MDImporterConcordanceListInterface { /** * Substrings of an actor name listed as a key in this array will be replaced @@ -22,7 +22,7 @@ final class MDConcActor { "()" => "", ]; - const ACTOR_ROLES_TO_EVENT_TYPE = [ + private const ACTOR_ROLES_TO_EVENT_TYPE = [ // 1: Created "Aktionskünstler" => 1, @@ -866,4 +866,20 @@ final class MDConcActor { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return integer + */ + public static function getConcordanceTarget(string $input):int { + + if (!isset(self::ACTOR_ROLES_TO_EVENT_TYPE[$input])) { + throw new MDImporterMissingConcordance("Unknown actor role: " . $input); + } + + return self::ACTOR_ROLES_TO_EVENT_TYPE[$input]; + + } } diff --git a/src/MDConcCheckTypes.php b/src/MDConcCheckTypes.php index 575d677..02489e1 100644 --- a/src/MDConcCheckTypes.php +++ b/src/MDConcCheckTypes.php @@ -9,10 +9,26 @@ declare(strict_types = 1); /** * Provides lists for categorizing misspelled check types. */ -final class MDConcCheckTypes { +final class MDConcCheckTypes implements MDImporterConcordanceListInterface { - const CHECK_TYPES = [ + private const CHECK_TYPES = [ "Vollständigkeit" => MDObjectCheckType::completeness_check, ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return MDObjectCheckType + */ + public static function getConcordanceTarget(string $input):MDObjectCheckType { + + if (!isset(self::CHECK_TYPES[$input])) { + throw new MDImporterMissingConcordance("Unknown check type: " . $input); + } + + return self::CHECK_TYPES[$input]; + + } } diff --git a/src/MDConcCloserLocationTypes.php b/src/MDConcCloserLocationTypes.php index 39340f4..e9ce355 100644 --- a/src/MDConcCloserLocationTypes.php +++ b/src/MDConcCloserLocationTypes.php @@ -10,9 +10,9 @@ declare(strict_types = 1); /** * Provides lists for categorizing spelled out closer location types. */ -final class MDConcCloserLocationTypes { +final class MDConcCloserLocationTypes implements MDImporterConcordanceListInterface { - const LOCATION_TYPES_VERBOSE = [ + private const LOCATION_TYPES_VERBOSE = [ # Place of recording "" => "0", @@ -33,4 +33,20 @@ final class MDConcCloserLocationTypes { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::LOCATION_TYPES_VERBOSE[$input])) { + throw new MDImporterMissingConcordance("Unknown location type: " . $input); + } + + return self::LOCATION_TYPES_VERBOSE[$input]; + + } } diff --git a/src/MDConcCurrencies.php b/src/MDConcCurrencies.php index 8a7b8be..4e01e71 100644 --- a/src/MDConcCurrencies.php +++ b/src/MDConcCurrencies.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides lists for categorizing spelled out currencies. */ -final class MDConcCurrencies { +final class MDConcCurrencies implements MDImporterConcordanceListInterface { - const CURRENCIES_LIST = [ + private const CURRENCIES_LIST = [ "^" => "", "-" => "", "x" => "", @@ -48,4 +48,20 @@ final class MDConcCurrencies { "US dollar" => "us-USD", ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::CURRENCIES_LIST[$input])) { + throw new MDImporterMissingConcordance("Unknown currency: " . $input); + } + + return self::CURRENCIES_LIST[$input]; + + } } diff --git a/src/MDConcDamageTypes.php b/src/MDConcDamageTypes.php index 9b13e77..0ae1a04 100644 --- a/src/MDConcDamageTypes.php +++ b/src/MDConcDamageTypes.php @@ -9,10 +9,26 @@ declare(strict_types = 1); /** * Provides lists for categorizing misspelled damage types. */ -final class MDConcDamageTypes { +final class MDConcDamageTypes implements MDImporterConcordanceListInterface { - const DAMAGE_TYPES = [ + private const DAMAGE_TYPES = [ "breakage" => MDObjectDamageType::breakage, ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return MDObjectDamageType + */ + public static function getConcordanceTarget(string $input):MDObjectDamageType { + + if (!isset(self::DAMAGE_TYPES[$input])) { + throw new MDImporterMissingConcordance("Unknown damage type: " . $input); + } + + return self::DAMAGE_TYPES[$input]; + + } } diff --git a/src/MDConcEntryTypes.php b/src/MDConcEntryTypes.php index 1837688..a25fba9 100644 --- a/src/MDConcEntryTypes.php +++ b/src/MDConcEntryTypes.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides lists for categorizing spelled out entry types. */ -final class MDConcEntryTypes { +final class MDConcEntryTypes implements MDImporterConcordanceListInterface { - const ENTRY_TYPES_VERBOSE = [ + private const ENTRY_TYPES_VERBOSE = [ // 0: No known entry type "" => "0", @@ -197,4 +197,20 @@ final class MDConcEntryTypes { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::ENTRY_TYPES_VERBOSE[$input])) { + throw new MDImporterMissingConcordance("Unknown entry type: " . $input); + } + + return self::ENTRY_TYPES_VERBOSE[$input]; + + } } diff --git a/src/MDConcEventTypes.php b/src/MDConcEventTypes.php index baa0719..7bea377 100644 --- a/src/MDConcEventTypes.php +++ b/src/MDConcEventTypes.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides a list for finding the respective event type ID for a given event type name. */ -final class MDConcEventTypes { +final class MDConcEventTypes implements MDImporterConcordanceListInterface { - const EVENT_TYPE_NAMES_TO_ID = [ + private const EVENT_TYPE_NAMES_TO_ID = [ // 1: Created 'Hergestellt' => 1, @@ -74,4 +74,20 @@ final class MDConcEventTypes { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return integer + */ + public static function getConcordanceTarget(string $input):int { + + if (!isset(self::EVENT_TYPE_NAMES_TO_ID[$input])) { + throw new MDImporterMissingConcordance("Unknown entry type: " . $input); + } + + return self::EVENT_TYPE_NAMES_TO_ID[$input]; + + } } diff --git a/src/MDConcLanguages.php b/src/MDConcLanguages.php index 1bb2947..2259d32 100644 --- a/src/MDConcLanguages.php +++ b/src/MDConcLanguages.php @@ -9,11 +9,27 @@ declare(strict_types = 1); /** * Provides lists for categorizing spelled out languages. */ -final class MDConcLanguages { +final class MDConcLanguages implements MDImporterConcordanceListInterface { - const LANGUAGES_LIST = [ + private const LANGUAGES_LIST = [ 'Deutsch' => 'de', 'German' => 'de', ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::LANGUAGES_LIST[$input])) { + throw new MDImporterMissingConcordance("Unknown language type: " . $input); + } + + return self::LANGUAGES_LIST[$input]; + + } } diff --git a/src/MDConcLengths.php b/src/MDConcLengths.php index 99267cc..999898c 100644 --- a/src/MDConcLengths.php +++ b/src/MDConcLengths.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides lists for categorizing misspelled sizes. */ -final class MDConcLengths { +final class MDConcLengths implements MDImporterConcordanceListInterface { - const LENGTHS_LIST = [ + private const LENGTHS_LIST = [ "cn" => "cm", ",cm" => "cm", "5cm" => "cm", @@ -21,4 +21,20 @@ final class MDConcLengths { "zoll" => "in", ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::LENGTHS_LIST[$input])) { + throw new MDImporterMissingConcordance("Unknown length type: " . $input); + } + + return self::LENGTHS_LIST[$input]; + + } } diff --git a/src/MDConcLicenses.php b/src/MDConcLicenses.php index 9278d70..eda7705 100644 --- a/src/MDConcLicenses.php +++ b/src/MDConcLicenses.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides lists for categorizing spelled out licenses. */ -final class MDConcLicenses { +final class MDConcLicenses implements MDImporterConcordanceListInterface { - const LICENSES_LIST = [ + private const LICENSES_LIST = [ "CC 0" => "CC0", "CC_0" => "CC0", "CC0 1.0" => "CC0", @@ -44,7 +44,7 @@ final class MDConcLicenses { "CC.BY-NC-SA" => "CC BY-NC-SA", "CC BY-NC-SA 3.0 AT" => "CC BY-NC-SA", "http://creativecommons.org/licenses/by-nc-sa/3.0/" => "CC BY-NC-SA", - "https://creativecommons.org/licenses/by-nc-sa/4.0/" => "CC BY-NC-SA", + "http://creativecommons.org/licenses/by-nc-sa/4.0/" => "CC BY-NC-SA", "https://creativecommons.org/licenses/by-nc-sa/4.0/" => "CC BY-NC-SA", "Namensnennung - Nicht kommerziell - Weitergabe unter gleichen Bedingungen 4.0 International (CC BY-NC-SA 4.0)" => "CC BY-NC-SA", @@ -69,4 +69,20 @@ final class MDConcLicenses { 'PDM 1.0' => 'Public Domain Mark', ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::LICENSES_LIST[$input])) { + throw new MDImporterMissingConcordance("Unknown licence type: " . $input); + } + + return self::LICENSES_LIST[$input]; + + } } diff --git a/src/MDConcLoanTypes.php b/src/MDConcLoanTypes.php index 0733861..734ac66 100644 --- a/src/MDConcLoanTypes.php +++ b/src/MDConcLoanTypes.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides a list for finding the loan type for an input. */ -final class MDConcLoanTypes { +final class MDConcLoanTypes implements MDImporterConcordanceListInterface { - const LOAN_TYPES = [ + private const LOAN_TYPES = [ // Outgoing "ausgehend" => "outgoing", @@ -21,4 +21,20 @@ final class MDConcLoanTypes { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::LOAN_TYPES[$input])) { + throw new MDImporterMissingConcordance("Unknown loan type: " . $input); + } + + return self::LOAN_TYPES[$input]; + + } } diff --git a/src/MDConcMarkingPosition.php b/src/MDConcMarkingPosition.php index d841d2c..48a3619 100644 --- a/src/MDConcMarkingPosition.php +++ b/src/MDConcMarkingPosition.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides lists for categorizing spelled out marking positions. */ -final class MDConcMarkingPosition { +final class MDConcMarkingPosition implements MDImporterConcordanceListInterface { - const MARKING_POSITIONS_VERBOSE = [ + private const MARKING_POSITIONS_VERBOSE = [ // Center "mittig" => "center", @@ -294,4 +294,20 @@ final class MDConcMarkingPosition { "oberer Holzkasten" => "other", ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::MARKING_POSITIONS_VERBOSE[$input])) { + throw new MDImporterMissingConcordance("Unknown marking position: " . $input); + } + + return self::MARKING_POSITIONS_VERBOSE[$input]; + + } } diff --git a/src/MDConcMarkingType.php b/src/MDConcMarkingType.php index 0ee00cc..f14465e 100644 --- a/src/MDConcMarkingType.php +++ b/src/MDConcMarkingType.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides lists for categorizing spelled out marking types. */ -final class MDConcMarkingType { +final class MDConcMarkingType implements MDImporterConcordanceListInterface { - const MARKING_TYPES_VERBOSE = [ + private const MARKING_TYPES_VERBOSE = [ // Default: Handwritten "x" => "handwritten", @@ -318,4 +318,20 @@ final class MDConcMarkingType { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::MARKING_TYPES_VERBOSE[$input])) { + throw new MDImporterMissingConcordance("Unknown marking type: " . $input); + } + + return self::MARKING_TYPES_VERBOSE[$input]; + + } } diff --git a/src/MDConcPlace.php b/src/MDConcPlace.php index fc343ab..bc23665 100644 --- a/src/MDConcPlace.php +++ b/src/MDConcPlace.php @@ -9,7 +9,7 @@ declare(strict_types = 1); /** * Provides a list for finding the respective event type for a given place role. */ -final class MDConcPlace { +final class MDConcPlace implements MDImporterConcordanceListInterface { /** * Substrings of an place name listed as a key in this array will be replaced @@ -23,7 +23,7 @@ final class MDConcPlace { "Unknown" => "", ]; - const PLACE_ROLES_TO_EVENT_TYPE = [ + private const PLACE_ROLES_TO_EVENT_TYPE = [ // 22: Related place '' => 22, @@ -105,4 +105,20 @@ final class MDConcPlace { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return integer + */ + public static function getConcordanceTarget(string $input):int { + + if (!isset(self::PLACE_ROLES_TO_EVENT_TYPE[$input])) { + throw new MDImporterMissingConcordance("Unknown place type: " . $input); + } + + return self::PLACE_ROLES_TO_EVENT_TYPE[$input]; + + } } diff --git a/src/MDConcTime.php b/src/MDConcTime.php index 0a12626..4ce068e 100644 --- a/src/MDConcTime.php +++ b/src/MDConcTime.php @@ -9,9 +9,9 @@ declare(strict_types = 1); /** * Provides a list for finding the respective event type for a given time role. */ -final class MDConcTime { +final class MDConcTime implements MDImporterConcordanceListInterface { - const TIME_ROLES_TO_EVENT_TYPE = [ + private const TIME_ROLES_TO_EVENT_TYPE = [ # General / not yet (?) categorized "Laufzeit" => 24, @@ -40,4 +40,20 @@ final class MDConcTime { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return integer + */ + public static function getConcordanceTarget(string $input):int { + + if (!isset(self::TIME_ROLES_TO_EVENT_TYPE[$input])) { + throw new MDImporterMissingConcordance("Unknown time type: " . $input); + } + + return self::TIME_ROLES_TO_EVENT_TYPE[$input]; + + } } diff --git a/src/MDConcTitleTypes.php b/src/MDConcTitleTypes.php index 9e78ad2..e6a0aac 100644 --- a/src/MDConcTitleTypes.php +++ b/src/MDConcTitleTypes.php @@ -10,9 +10,9 @@ declare(strict_types = 1); /** * Constains lists for resolving title type names to their internally used names. */ -final class MDConcTitleTypes { +final class MDConcTitleTypes implements MDImporterConcordanceListInterface { - const TITLE_TYPES = [ + private const TITLE_TYPES = [ // Empty "" => "", @@ -34,4 +34,20 @@ final class MDConcTitleTypes { ]; + /** + * Require a function for getting the concordance target. + * + * @param string $input Input string. + * + * @return string + */ + public static function getConcordanceTarget(string $input):string { + + if (!isset(self::TITLE_TYPES[$input])) { + throw new MDImporterMissingConcordance("Unknown title type: " . $input); + } + + return self::TITLE_TYPES[$input]; + + } }