-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergeduplicateIDs.py
56 lines (47 loc) · 2.02 KB
/
mergeduplicateIDs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Find all journal items that have a suggested ISSN because it appears
in an item about and article which appears in the journal.
Find all of these suggested ISSNs and add them to the lowest
Qid journal item.
Then find all journal article items (that have an ISSN) that 'appear' in a journal
item with no ISSN. Lookup the ISSN and if it exists alter the calim so it points
to the right (low Qid) Journal item.
Then merge the higher Qid journal item with the lower one.
"""
import librarybase
import pywikibot
site = pywikibot.Site("librarybase", "librarybase")
searcher = librarybase.LibraryBaseSearch()
journaldict = searcher.predictISSNOfJournalsFromISSNOfArticle()
issndict=dict()
for line in journaldict:
#print(line[0])
issndict.setdefault(line[1], []).append(line[0])
print(issndict)
issnlist=[]
for issn, idlist in issndict.items():
issnlist.append([issn, min(idlist)])
# for line in issnlist:
# journalitem=librarybase.JournalPage(site, 'Q{}'.format(line[1]))
# journalitem.setISSN(line[0])
# journalitem.setItemType()
journalarticles = searcher.findJournalArticleswithISSNThatPointToJournalWithoutISSN()
for journalarticle in journalarticles:
issn=journalarticle.getISSN()
#print(issn)
journal=searcher.findJournalByISSN(issn)
targetjournal = next(journal)
if(targetjournal):
defunctPages=[defunctjournal for defunctjournal in journalarticle.getClaimTargets('P4')]
#print(defunctPages)
#journalarticle.removeClaims(journalarticle.getClaims('P4'))
journalarticle.makeSimpleClaim('P4', targetjournal)
#print(journalarticle.getClaims('P4'))
for defunctPage in defunctPages:
possibleBadClaims=journalarticle.getClaims('P4')
badClaims = []
for claim in possibleBadClaims:
if claim.getTarget()==defunctPage:
badClaims.append(claim)
journalarticle.removeClaims(badClaims)
defunctPage.mergeInto(targetjournal)