-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for moving age from genreForm to intendedAudience (#1345)
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
whelktool/scripts/cleanups/2023/11/lxl-4379-gf-to-intendedAudience.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Set iaLabels = ['0-3 år', '3-6 år', '6-9 år', '9-12 år', '12-15 år', '15'] | ||
|
||
def where = """ | ||
collection = 'bib' | ||
and deleted = false | ||
and data #>> '{@graph,1,instanceOf,genreForm}' is not null | ||
""" | ||
|
||
selectBySqlWhere(where) { bib -> | ||
def work = bib.graph[1].instanceOf | ||
def toIntendedAudience = [] | ||
work.genreForm.removeAll { gf -> | ||
if (gf.prefLabel in iaLabels) { | ||
toIntendedAudience.add(gf.prefLabel) | ||
} | ||
} | ||
if (work.genreForm.isEmpty()) { | ||
work.remove('genreForm') | ||
} | ||
if (toIntendedAudience) { | ||
toIntendedAudience.each { label -> | ||
if (!asList(work.intendedAudience).any { ia -> ia.label == label }) { | ||
work['intendedAudience'] = asList(work.intendedAudience) + ['@type': 'IntendedAudience', 'label': label] | ||
} | ||
} | ||
bib.scheduleSave() | ||
} | ||
} |