Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 66 additions & 9 deletions src/RecordManager/Base/Record/Lido.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ class Lido extends AbstractRecord
*/
protected string $lidoNs = 'http://www.lido-schema.org';

/**
* SKOS namespace.
*
* @var string
*/
protected string $skosNs = 'http://www.w3.org/2004/02/skos/core#';

/**
* RDF namespace.
*
* @var string
*/
protected string $rdfNs = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';

/**
* Main event names reflecting the terminology in the particular LIDO records.
*
Expand Down Expand Up @@ -456,7 +470,11 @@ protected function postProcessRecordForIndexing(?Database $db, &$data): void
protected function getISBNs(): array
{
$arr = [];
foreach ($this->getIdentifiersByType(['isbn'], []) as $identifier) {
$isbns = [
...$this->xmlDoc->allValues(path: 'lido/objectPublishedID'),
...$this->getIdentifiersByType(['isbn'], []),
];
foreach ($isbns as $identifier) {
if ($isbn = $this->metadataUtils->normalizeISBN($this->checkISBN((string)$identifier))) {
$arr[] = $isbn;
} else {
Expand Down Expand Up @@ -492,14 +510,9 @@ protected function getTopicIDs($exclude = ['iconclass']): array
{
$result = [];
foreach ($this->getSubjectNodes($exclude) as $subjectNode) {
foreach ($this->xmlDoc->all($subjectNode, 'subjectConcept/conceptID') as $conceptID) {
if (
($id = $this->xmlDoc->value($conceptID))
&& ($type = $this->xmlDoc->attr($conceptID, 'type'))
) {
if (in_array(mb_strtolower($type, 'UTF-8'), $this->subjectConceptIDTypes)) {
$result[] = $id;
}
foreach ($this->xmlDoc->all($subjectNode, 'subjectConcept') as $concept) {
if ('' !== $id = $this->getFirstConceptIdentifier($concept, $this->subjectConceptIDTypes)) {
$result[] = $id;
}
}
}
Expand Down Expand Up @@ -1541,4 +1554,48 @@ protected function getThumbnailUrl(): string
$urls = $this->getUrls();
return $urls[0] ?? '';
}

/**
* Get first conceptID identifier or skos:Concept URI of a node
*
* @param array $parentNode The node that contains conceptID and skos:Concept nodes
* @param array $allowedTypes Allowed conceptID types
*
* @return string
*/
protected function getFirstConceptIdentifier(array $parentNode, array $allowedTypes = []): string
{
foreach ($this->xmlDoc->all($parentNode, 'conceptID') as $conceptID) {
if ($id = $this->xmlDoc->value($conceptID)) {
$type = mb_strtolower($this->xmlDoc->attr($conceptID, 'type') ?? '', 'UTF-8');
if (!$allowedTypes || in_array($type, $allowedTypes)) {
return $id;
}
}
}
return $this->getSkosConceptURI($parentNode);
}

/**
* Get a skos:Concept URI from a node.
*
* @param array $node Node
*
* @return string
*/
protected function getSkosConceptURI(array $node): string
{
$skosConcepts = [
...$this->xmlDoc->all($node, "{{$this->skosNs}}Concept"),
...$this->xmlDoc->all($node, 'Concept'),
];
foreach ($skosConcepts as $skosConcept) {
$uri = $this->xmlDoc->attr($skosConcept, "{{$this->rdfNs}}about")
?? $this->xmlDoc->attr($skosConcept, 'about');
if (null !== $uri) {
return $uri;
}
}
return '';
}
}
10 changes: 10 additions & 0 deletions tests/RecordManagerTest/Base/Record/LidoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function testLido1()
'(knp)M011-320623',
],
'isbn' => [
'9789517718721',
'9789518593730',
'9789518593731',
'9789518593732',
Expand All @@ -112,6 +113,8 @@ public function testLido1()
'thumbnail' => '',
'allfields' => [
'knp-247394',
'12345678',
'URN:ISBN:951-771-872-1',
'Kirja',
'Säädökset',
'Luonnonsuojelusäädökset / toimittanut Raimo Luhtanen',
Expand Down Expand Up @@ -240,6 +243,7 @@ public function testLido1NonMergedTitle()
'(knp)M011-320623',
],
'isbn' => [
'9789517718721',
'9789518593730',
'9789518593731',
'9789518593732',
Expand All @@ -251,6 +255,8 @@ public function testLido1NonMergedTitle()
'thumbnail' => '',
'allfields' => [
'knp-247394',
'12345678',
'URN:ISBN:951-771-872-1',
'Kirja',
'Säädökset',
'Luonnonsuojelusäädökset / toimittanut Raimo Luhtanen',
Expand Down Expand Up @@ -525,6 +531,10 @@ public function testNamespaces(): void
],
$getTitles->invokeArgs($record, ['fi'])
);
$this->assertEquals(
['http://www.yso.fi/onto/yso/p19378'],
$reflection->getMethod('getTopicIDs')->invokeArgs($record, [])
);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/Base/record/lido1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<lidoWrap schemaLocation="http://www.lido-schema.org http://www.lido-schema.org/schema/v1.0/lido-v1.0.xsd">
<lido>
<lidoRecID type="Test">knp-247394</lidoRecID>
<objectPublishedID type="URI" label="not isbn">12345678</objectPublishedID>
<objectPublishedID type="URI" label="isbn">URN:ISBN:951-771-872-1</objectPublishedID>
<descriptiveMetadata lang="fi">
<objectClassificationWrap>
<objectWorkTypeWrap>
Expand Down
14 changes: 13 additions & 1 deletion tests/fixtures/Base/record/lido_ns.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<lido:lidoWrap xmlns:lido="http://www.lido-schema.org" xmlns:gml="http://www.opengis.net/gml">
<lido:lidoWrap xmlns:lido="http://www.lido-schema.org" xmlns:gml="http://www.opengis.net/gml" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<lido:lido>
<lido:lidoRecID lido:type="item">testimuseo-K1554</lido:lidoRecID>
<lido:descriptiveMetadata xml:lang="fi">
Expand All @@ -11,6 +11,18 @@
</lido:titleSet>
</lido:titleWrap>
</lido:objectIdentificationWrap>
<lido:objectRelationWrap>
<lido:subjectWrap>
<lido:subjectSet>
<lido:subject>
<lido:subjectConcept>
<skos:Concept rdf:about="http://www.yso.fi/onto/yso/p19378"/>
<lido:term>kissa</lido:term>
</lido:subjectConcept>
</lido:subject>
</lido:subjectSet>
</lido:subjectWrap>
</lido:objectRelationWrap>
</lido:descriptiveMetadata>
</lido:lido>
</lido:lidoWrap>
Loading