This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
software.py
233 lines (207 loc) · 6.91 KB
/
software.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
from datetime import datetime
from flask import make_response, abort
def get_timestamp():
return datetime.now().strftime(("%Y-%m-%d %H:%M:%S"))
SOFTWARE = {
"Q8029" : {
"id": "Q8029",
"labels": {"en": {"language": "en", "value": "BibTeX"}},
"descriptions": {"en": {"language": "en", "value": "reference management software for formatting lists of references"}},
"aliases": [],
"claims": {"P31": [{"datatype":"wikibase-item", "datavalue": {"value": "Q7397"}}, # instance of software
{"datatype":"wikibase-item", "datavalue": {"value": "Q18616720"}}], # instance of bibliographic data format
"P178": [{"datatype":"wikibase-item", "datavalue": {"value": "Q93068"}}], # developer is Q93068 (Oren Patashnik)
"P856": [{"datatype":"url", "datavalue": {"value": "https://www.ctan.org/pkg/bibtex"}}] # url
}
}
}
CITATIONS = {
"Q8029": {
"id": "Q8029",
"citations": [ {
"document": { "doi": "https://doi.org/10.1093/pcp/pcg126",
"url": "",
"sha1": ""},
"mentions": [{
"type": "software",
"id": "Q8029",
"conf": 0.9511,
"software-name": {
"rawForm": "bibtex",
"offsetStart": 351,
"offsetEnd": 364,
"boundingBoxes": [{
"p": 8,
"x": 118.928,
"y": 461.363,
"w": 49.98600000000002,
"h": 7.749360000000024
}]
},
"creator": {
"rawForm": "O. Patashnik",
"offsetStart": 366,
"offsetEnd": 407,
"boundingBoxes": [{
"p": 8,
"x": 175.37953333333334,
"y": 461.363,
"w": 115.15626666666665,
"h": 7.749360000000024
}, {
"p": 8,
"x": 48.5996,
"y": 471.623,
"w": 21.192299999999996,
"h": 7.749360000000024
}]
}
}]
},
{
"document": { "doi": "https://doi.org/10.1038/s41699-018-0076-0",
"url": "",
"sha1": ""},
"mentions": [{
"type": "software",
"id": "Q8029",
"conf": 0.7719,
"software-name": {
"rawForm": "BibTeX",
"offsetStart": 113,
"offsetEnd": 135,
"boundingBoxes": [{
"p": 8,
"x": 271.854,
"y": 363.347,
"w": 125.13299999999998,
"h": 13.283999999999992
}]
},
}]
}
]
}
}
DOCUMENTS = {
"Q8029": {
"id": "Q8029",
"documents": [
{
"document": { "doi": "https://doi.org/10.1093/pcp/pcg126",
"url": "",
"sha1": ""},
"relevance": 0.95
},
{
"document": { "doi": "https://doi.org/10.1038/s41699-018-0076-0",
"url": "",
"sha1": ""},
"relevance": 0.89
}
]
}
}
SOFTWARE_RELATEDNESS = {
"Q8029": {
"id": "Q8029",
"software": [
{
"id": "Q5310",
"relatedness": 0.9761
},
{
"id": "Q226915",
"relatedness": 0.7130
}
]
}
}
def read_one(id):
"""
This function responds to a request for /api/software/{id}
with one matching id from all software entities
:param id: identifier of the software entity to find
:return: software entity matching the identifier
"""
if id in SOFTWARE:
soft = SOFTWARE.get(id)
soft["date"] = get_timestamp()
# otherwise nope
else:
abort(
404, "Software entity with identifier {id} not found".format(id=id)
)
return soft
def read_citations(id):
"""
This function responds to a request for /api/software/{id}/citations
with one matching id from all software entities
:param id: identifier of the software entity to find
:return: all the citations to the software entity matching the identifier
"""
if id in CITATIONS:
soft = CITATIONS.get(id)
soft["date"] = get_timestamp()
# otherwise nope
else:
abort(
404, "Software entity with identifier {id} not found".format(id=id)
)
return soft
def disambiguate(json_mention):
response = {
"id": "Q8029",
"conf": 0.96
}
response["date"] = get_timestamp()
return response
def nbest_documents(id):
"""
This function responds to a request for /api/software/{id}/documents:
with one matching id from all software entities
:param id: identifier of the software entity to find
:return: list of n-best documents related to the software entity matching the identifier
"""
if id in DOCUMENTS:
soft = DOCUMENTS.get(id)
soft["date"] = get_timestamp()
# otherwise nope
else:
abort(
404, "Software entity with identifier {id} not found".format(id=id)
)
return soft
def nbest_software(id):
"""
This function responds to a request for /api/software/{id}/related:
with one matching id from all software entities
:param id: identifier of the software entity to find
:return: list of n-best software related to the software entity matching the identifier
"""
if id in SOFTWARE_RELATEDNESS:
soft = SOFTWARE_RELATEDNESS.get(id)
soft["date"] = get_timestamp()
# otherwise nope
else:
abort(
404, "Software entity with identifier {id} not found".format(id=id)
)
return soft
def delete(json_object):
"""
This function responds to a POST request for /api/document:
:param json: the json object as produced by the software mention recognizer when producing a full document
"""
response = {}
response["date"] = get_timestamp()
return response
'''
example:
wikidata_identifier:
value: Q8029
summary: identifier for a software entity already in Wikidata
non_wikidata_identifier:
value: E280
summary: identifier for a software entity not already in Wikidata
'''