-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
100 lines (82 loc) · 2.58 KB
/
utils.py
File metadata and controls
100 lines (82 loc) · 2.58 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import hashlib
inverse = {"iscitedby":"cites",
"cites":"iscitedby",
"issupplementto":"issupplementedby",
"issupplementedby":"issupplementto",
"iscontinuedby":"continues",
"continues":"iscontinuedby",
"isnewversionof":"ispreviousversionof",
"ispreviousversionof":"isnewversionof",
"ispartof":"haspart",
"haspart":"ispartof",
"isreferencedby":"references",
"references":"isreferencedby",
"isdocumentedby":"documents",
"documents":"isdocumentedby",
"iscompiledby":"compiles",
"compiles":"iscompiledby",
"isvariantformof":"isoriginalformof",
"isoriginalformof":"isvariantformof",
"isidenticalto":"isidenticalto",
"hasmetadata":"ismetadatafor",
"ismetadatafor":"hasmetadata",
"reviews":"isreviewedby",
"isreviewedby":"reviews",
"isderivedfrom":"issourceof",
"issourceof":"isderivedfrom",
}
def get_inverse(relation):
return inverse[relation]
def toRemovePrefix(id):
found = False
if (id.strip()[:4] == 'doi:'):
id = id.strip()[4:]
found = True
return id, found
def toStripId(id):
found = False
if (id.strip() != id):
id = id.strip()
found = True
return id, found
def findrelationset(drel, irel):
if drel == []:
return irel
if irel == []:
return drel
for r in drel:
i = isin(r,irel)
if i>-1:
del irel[i]
if irel == []:
return drel
for e in irel:
drel.append(e)
return drel
def isin(r,rels):
i = 0
for i in range(len(rels)):
rel = rels[i]
if rel['relation_type'].lower() == r['relation_type'].lower() and rel['relatedIdentifierValue'] == r['relatedIdentifierValue']:
return i
return -1
def updateIfDifferent(toupdate,doc,abs="abs"):
dic = {}
if toupdate['type'] != doc["type"] and doc["type"] == 'publication':
dic['type'] = 'publication'
if toupdate['title'] == [] and doc['title'] != []:
dic['title'] = doc['title']
if toupdate['abstracts'] == [] and doc[abs] != []:
dic['abstracts'] = doc[abs]
rel = findrelationset(toupdate['rels'], doc['rels'])
if rel != []:
dic['rels']=rel
return dic
def resource_identifier(pid, pid_type):
m = hashlib.md5()
r = pid.lower() + "::" + pid_type.lower()
try:
m.update(r)
except:
m.update(r.encode('utf-8'))
return m.hexdigest()