Add class NodaTagRelationIdentifier for parsing tag relation types from
input tag names
This commit is contained in:
54
src/NodaTagRelationIdentifier.php
Normal file
54
src/NodaTagRelationIdentifier.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Identifies the type of tag relation to an object based on known suffixes.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Contains static functions for identifying uncertainty or blocking
|
||||
* completely uncertain inputs for actors, times, and places.
|
||||
*/
|
||||
final class NodaTagRelationIdentifier {
|
||||
|
||||
private const SUFFIXES = [
|
||||
'de' => [
|
||||
' (Motiv)' => MDTagRelationType::display_subject,
|
||||
]
|
||||
];
|
||||
|
||||
public readonly string $name;
|
||||
public readonly MDTagRelationType|false $relation;
|
||||
|
||||
/**
|
||||
* Constructor: Removes identifiers for well-known tag relations and determines cleaned name and relation type.
|
||||
*
|
||||
* @param string $lang Current language.
|
||||
* @param string $input_string Input string to clean.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(string $lang, string $input_string) {
|
||||
|
||||
if (empty(self::SUFFIXES[$lang])) {
|
||||
$this->name = $input_string;
|
||||
$this->relation = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$relation = false;
|
||||
|
||||
$suffixes = self::SUFFIXES[$lang];
|
||||
foreach (array_keys($suffixes) as $suffix) {
|
||||
if (\mb_substr($input_string, \mb_strlen($suffix) * -1) === "$suffix") {
|
||||
$input_string = \mb_substr($input_string, 0, \mb_strlen($suffix) * -1);
|
||||
$relation = $suffixes[$suffix];
|
||||
}
|
||||
}
|
||||
|
||||
$this->name = $input_string;
|
||||
$this->relation = $relation;
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user