-
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.
Merge pull request #1281 from libris/feature/lxl-4150-deduplicate-con…
…tribution Feature/lxl 4150 deduplicate contribution
- Loading branch information
Showing
3 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
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
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
librisworks/scripts/lxl-4150-deduplicate-contribution.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,35 @@ | ||
def ids = new File(System.getProperty('clusters')).collect { it.split('\t').collect { it.trim() } }.flatten() | ||
|
||
selectByIds(ids) { bib -> | ||
def work = bib.graph[1].instanceOf | ||
def contribution = work?.contribution | ||
|
||
if (!contribution) return | ||
|
||
def duplicates = contribution.countBy { asList(it.agent) }.findResults { it.value > 1 ? it.key : null } | ||
|
||
duplicates.each { d -> | ||
def primaryContributionIdx = contribution.findIndexOf { asList(it.agent) == d && it['@type'] == 'PrimaryContribution' } | ||
def mergeIntoIdx = primaryContributionIdx > -1 | ||
? primaryContributionIdx | ||
: contribution.findIndexOf { asList(it.agent) == d } | ||
def mergeInto = contribution[mergeIntoIdx] | ||
def roles = [] | ||
|
||
contribution.removeAll { | ||
if (asList(it.agent) == d) { | ||
roles += asList(it.role) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
if (roles) mergeInto['role'] = roles.unique() | ||
|
||
contribution.add(mergeIntoIdx, mergeInto) | ||
} | ||
|
||
if (duplicates) { | ||
bib.scheduleSave() | ||
} | ||
} |