Skip to content

Commit

Permalink
[FINNA-1020] LIDO: index repository locations (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuomaJuha authored Oct 17, 2023
1 parent a897189 commit 01b0e5a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 11 deletions.
6 changes: 6 additions & 0 deletions conf/recordmanager.ini.sample.finna
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
;excluded_file_extensions[] = "mp3"
;excluded_file_extensions[] = "css"
;excluded_file_extensions[] = "sib"

; Lido only settings
[LidoRecord]
; The following section excludes certain location places
; Compares to: ...namePlaceSet->appellationValue->attributes()->label
;excluded_location_labels[] = "Torin nurkkaus etäällä"
81 changes: 70 additions & 11 deletions src/RecordManager/Finna/Record/Lido.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ class Lido extends \RecordManager\Base\Record\Lido
*/
protected $descriptionTypesExcludedFromTitle = ['provenance', 'provenienssi'];

/**
* Location labels which should be excluded when getting location information.
*
* @var array
*/
protected $excludedLocationLabels;

/**
* Constructor
*
Expand All @@ -134,6 +141,11 @@ public function __construct(
$logger,
$metadataUtils
);
$this->excludedLocationLabels
= $this->config['LidoRecord']['excluded_location_labels'] ?? [
'tarkempi paikka',
];

$this->initMediaTypeTrait($config);
}

Expand Down Expand Up @@ -271,8 +283,10 @@ public function toSolrArray(Database $db = null)
$data['hires_image_str_mv'] = $this->source;
}
}

$data['location_geo'] = $this->getEventPlaceLocations();
$data['location_geo'] = [
...$this->getEventPlaceLocations(),
...$this->getRepositoryLocations(),
];
$data['center_coords']
= $this->metadataUtils->getCenterCoordinates($data['location_geo']);

Expand Down Expand Up @@ -362,18 +376,36 @@ function ($s) {
}
}

$displayLocations = [];
foreach (
$this->doc->lido->descriptiveMetadata->objectIdentificationWrap
->repositoryWrap->repositorySet ?? [] as $set
) {
if (empty($set->repositoryLocation)) {
continue;
}
if (!empty($set->repositoryLocation->gml)) {
return [];
}
if ($result = $this->getHierarchicalLocations($set->repositoryLocation)) {
foreach ($result as $location) {
$displayLocations[] = implode(', ', $location);
}
}
}
$accepted = [];
foreach ($locations as $location) {
if (preg_match_all("/[\pL']+/u", trim($location)) === 1) {
foreach ($subjectLocations as $subjectLocation) {
if (str_starts_with($subjectLocation, $location)) {
continue 2;
foreach ([$locations, $displayLocations] as $results) {
foreach ($results as $location) {
if (preg_match_all("/[\pL']+/u", trim($location)) === 1) {
foreach ($subjectLocations as $compare) {
if (str_starts_with($compare, $location)) {
continue 2;
}
}
}
$accepted[] = $location;
}
$accepted[] = $location;
}

return [
'primary' => $this->processLocations($subjectLocations),
'secondary' => $this->processLocations($accepted),
Expand Down Expand Up @@ -464,6 +496,11 @@ protected function getHierarchicalLocations(\SimpleXMLElement $elem): array
// appellationvalues under same parent
// If this is not the case, then things are not going ok
$currentLabel = trim((string)$elemValue->attributes()->label);
if (in_array(strtolower($currentLabel), $this->excludedLocationLabels)) {
// Locations with labels like "Torin kulman takaosa" should be skipped
continue;
}

if ($label && $label !== $currentLabel) {
// There seems to be different types of appellationValues so skip the new ones
continue;
Expand Down Expand Up @@ -506,6 +543,29 @@ protected function getHierarchicalLocations(\SimpleXMLElement $elem): array
return $results;
}

/**
* Get repository locations
*
* @return array<int, string>
*/
protected function getRepositoryLocations(): array
{
$results = [];
foreach (
$this->doc->lido->descriptiveMetadata->objectIdentificationWrap
->repositoryWrap->repositorySet ?? [] as $set
) {
if (empty($set->repositoryLocation->gml)) {
continue;
}
if ($wkt = $this->convertGmlToWkt($set->repositoryLocation->gml)) {
$results[] = $wkt;
}
}

return $results;
}

/**
* Split a location found from displayPlace element. Excludes all values
* found after splitting which has redundancy or has only a single value.
Expand Down Expand Up @@ -594,9 +654,8 @@ function ($s) {
},
$result
);
$result = array_unique($result);

return $result;
return array_values(array_unique($result));
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/RecordManagerTest/Finna/Record/LidoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ public function testHierarchicalLocations(): void
'Håkansbölen kartano, Hakunila, Vantaa, Suomi',
'Vaasa',
'Ristimäenkatu 5, Mikkeli, Etelä-Savo, Suomi',
'Ahmatie 1, Helsinki',
],
];
$this->compareArray($expected, $result, 'Locations');
Expand Down
21 changes: 21 additions & 0 deletions tests/fixtures/Finna/record/lido_locations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
<lido>
<lidoRecID type="ITEM">M123</lidoRecID>
<descriptiveMetadata>
<objectIdentificationWrap>
<repositoryWrap>
<repositorySet type="Current location">
<repositoryLocation>
<namePlaceSet>
<appellationValue label="tarkempi paikka">Should not display</appellationValue>
</namePlaceSet>
<partOfPlace>
<namePlaceSet>
<appellationValue label="katuosoite">Ahmatie 1</appellationValue>
</namePlaceSet>
<partOfPlace>
<namePlaceSet>
<appellationValue label="kunta/kaupunki">Helsinki</appellationValue>
</namePlaceSet>
</partOfPlace>
</partOfPlace>
</repositoryLocation>
</repositorySet>
</repositoryWrap>
</objectIdentificationWrap>
<objectRelationWrap>
<subjectWrap>
<subjectSet>
Expand Down

0 comments on commit 01b0e5a

Please sign in to comment.