forked from YourOpenDAta/mqa-scoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmqaMetrics.py
209 lines (177 loc) · 6.14 KB
/
mqaMetrics.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
'''
YODA (Your Open DAta)
EU CEF Action 2019-ES-IA-0121
University of Cantabria
Developer: Johnny Choque (jchoque@tlmat.unican.es)
'''
import requests
from rdflib import Graph, URIRef
def access_url(urls, weight):
checked = True
for url in urls:
try:
res = requests.get(url)
if res.status_code in range(200, 399):
checked = checked and True
else:
checked = checked and False
except:
checked = checked and False
if checked:
weight = weight + 50
print(' Result: OK. Weight assigned 50')
else:
print(' Result: ERROR - Responded status code of HTTP HEAD request is not in the 200 or 300 range')
return weight
def download_url(urls, weight):
checked = True
print(' Result: OK. The property is set. Weight assigned 20')
weight = weight + 20
for url in urls:
try:
res = requests.get(url)
if res.status_code in range(200, 399):
checked = checked and True
else:
checked = checked and False
except:
checked = checked and False
if checked:
weight = weight + 30
print(' Result: OK. Weight assigned 30')
else:
print(' Result: ERROR - Responded status code of HTTP HEAD request is not in the 200 or 300 range')
return weight
def keyword(weight):
weight = weight + 30
print(' Result: OK. The property is set. Weight assigned 30')
return weight
def theme(weight):
weight = weight + 30
print(' Result: OK. The property is set. Weight assigned 30')
return weight
def spatial(weight):
weight = weight + 20
print(' Result: OK. The property is set. Weight assigned 20')
return weight
def temporal(weight):
weight = weight + 20
print(' Result: OK. The property is set. Weight assigned 20')
return weight
def format(urls, mach_read_voc, non_prop_voc, weight):
mach_read_checked = True
non_prop_checked = True
found_checked = True
print(' Result: OK. The property is set. Weight assigned 20')
weight = weight + 20
for url in urls:
if str(url) in mach_read_voc:
mach_read_checked = mach_read_checked and True
else:
mach_read_checked = mach_read_checked and False
if str(url) in non_prop_voc:
non_prop_checked = non_prop_checked and True
else:
non_prop_checked = non_prop_checked and False
g = Graph()
g.parse(url, format="application/rdf+xml")
if (url, None, None) in g:
found_checked = found_checked and True
else:
found_checked = found_checked and False
if mach_read_checked:
print(' Result: OK. The property is machine-readable. Weight assigned 20')
weight = weight + 20
else:
print(' Result: ERROR. The property is not machine-readable')
if non_prop_checked:
print(' Result: OK. The property is non-proprietary. Weight assigned 20')
weight = weight + 20
else:
print(' Result: ERROR. The property is not non-proprietary')
if found_checked:
result = True
else:
result = False
return {'result': result, 'url': str(url), 'weight': weight}
def license(urls, weight):
checked = True
weight = weight + 20
print(' Result: OK. The property is set. Weight assigned 20')
for url in urls:
g = Graph()
g.parse(url, format="application/rdf+xml")
if (url, None, None) in g:
checked = checked and True
else:
checked = checked and False
if checked:
weight = weight + 10
print(' Result: OK. The property provides the correct license information. Weight assigned 10')
else:
print(' Result: ERROR. The license is incorrect -', str(url))
return weight
def contactpoint(weight):
weight = weight + 20
print(' Result: OK. The property is set. Weight assigned 20')
return weight
def mediatype(urls, weight):
checked = True
weight = weight + 10
print(' Result: OK. The property is set. Weight assigned 10')
for url in urls:
res = requests.get(str(url))
if res.status_code != 404:
checked = checked and True
else:
checked = checked and False
if checked:
result = True
else:
result = False
return {'result': result, 'weight': weight}
def publisher(weight):
weight = weight + 10
print(' Result: OK. The property is set. Weight assigned 10')
return weight
def access_rights(urls, weight):
uri = URIRef('')
checked = True
is_url = True
weight = weight + 10
print(' Result: OK. The property is set. Weight assigned 10')
for url in urls:
g = Graph()
if type(url) != type(uri):
is_url = False
continue
g.parse(url, format="application/rdf+xml")
if (url, None, None) in g:
checked = checked and True
else:
checked = checked and False
if is_url:
if checked:
weight = weight + 5
print(' Result: OK. The property uses a controlled vocabulary. Weight assigned 5')
else:
print(' Result: ERROR. The license is incorrect -', str(url))
else:
print(' Result: ERROR. The property does not use a valid URL. No additional weight assigned')
return weight
def issued(weight):
weight = weight + 5
print(' Result: OK. The property is set. Weight assigned 5')
return weight
def modified(weight):
weight = weight + 5
print(' Result: OK. The property is set. Weight assigned 5')
return weight
def rights(weight):
weight = weight + 5
print(' Result: OK. The property is set. Weight assigned 5')
return weight
def byte_size(weight):
weight = weight + 5
print(' Result: OK. The property is set. Weight assigned 5')
return weight