-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoIDAnalyses.py
200 lines (178 loc) · 4.82 KB
/
VoIDAnalyses.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
import datetime
import re
from rdflib import DCAT, Graph, URIRef
from rdflib.namespace import DC, DCTERMS, DOAP, FOAF, SKOS, OWL, RDF, RDFS, VOID, XMLNS, XSD
def parseVoID(url):
g = Graph()
g.parse(url)
return g
def parseVoIDTtl(url):
g = Graph()
g.parse(url,format='ttl')
return g
def printVoID(graph):
for s,p,o in graph:
print(s,p,o)
def getVocabularies(graph):
vocabularies = []
for s, p, o in graph:
if p == VOID.vocabulary:
o = str(o)
vocabularies.append(o)
newVocabularies = []
[newVocabularies.append(x) for x in vocabularies if x not in newVocabularies] #DUPLICATE REMOVAL IF PRESENT
return(newVocabularies)
def getCreationDate(graph):
date = []
for s,p,o in graph:
if p == DCTERMS.created or DCTERMS.issued:
o = str(o)
match = re.search(r'\d{4}-\d{2}-\d{2}', o)
if match is not None:
o = datetime.datetime.strptime(match.group(), '%Y-%m-%d').date()
date.append(o)
if len(date) > 0:
return min(date)
else:
return 'absent'
def getModificationDate(graph):
date = []
for s,p,o in graph:
if p == DCTERMS.modified:
o = str(o)
match = re.search(r'\d{4}-\d{2}-\d{2}', o)
if match is not None:
o = datetime.datetime.strptime(match.group(), '%Y-%m-%d').date()
date.append(o)
if len(date) > 0:
return max(date)
else:
return 'absent'
def getDataDump(graph):
for s,p,o in graph:
if p == VOID.dataDump:
o = str(o)
return o
return 'absent'
def getLicense(graph):
for s,p,o in graph:
if p == DCTERMS.license:
o = str(o)
return o
return 'absent'
def getCreators(graph):
creators = []
for s,p,o in graph:
if p == DCTERMS.creator or DC.creator:
o = str(o)
creators.append(o)
if len(creators) > 0:
return creators
else:
return 'absent'
def getPublishers(graph):
publishers = []
for s,p,o in graph:
if p == DCTERMS.publisher or p == DC.publisher:
o = str(o)
publishers.append(o)
if len(publishers) > 0:
return publishers
else:
return 'absent'
def getContributors(graph):
contributors = []
for s,p,o in graph:
if p == DCTERMS.contributor or p == DC.contributor:
o = str(o)
contributors.append(o)
if len(contributors) > 0:
return contributors
else:
return 'absent'
def getNumEntities(graph):
for s,p,o in graph:
if p == VOID.entities:
o = str(o)
if o != '':
return o
else:
return 'absent'
return 'information abaout entities absent'
def getFrequency(graph):
for s,p,o in graph:
if p == DCTERMS.Frequency or p == DCTERMS.accrualPeriodicity:
o = str(o)
if o != '':
return o
return 'absent'
def getUriRegex(graph):
regex = []
for s,p,o in graph:
if p == VOID.uriRegexPattern or VOID.uriSpace:
o = str(o)
regex.append(o)
if len(regex) > 0:
return regex
else:
return 'absent'
def getSerializationFormats(graph):
formats = []
for s,p,o in graph:
if p == VOID.feature or DCAT.mediaType:
o = str(o)
formats.append(o)
if len(formats) > 0:
return formats
else:
return 'absent'
def getLanguage(graph):
formats = []
for s,p,o in graph:
if p == DCTERMS.language or DC.language:
o = str(o)
formats.append(o)
if len(formats) > 0:
return formats
else:
return 'absent'
def getDistinctO(graph):
objects = []
for s,p,o in graph:
if p == VOID.distinctObjects:
o = str(o)
objects.append(o)
if len(objects) > 0:
return objects
else:
return 'absent'
def getDistinctS(graph):
subjects = []
for s,p,o in graph:
if p == VOID.distinctSubjects:
o = str(o)
subjects.append(o)
if len(subjects) > 0:
return subjects
else:
return 'absent'
def getProperties(graph):
properties = []
for s,p,o in graph:
if p == VOID.properties:
o = str(o)
properties.append(o)
if len(properties) > 0:
return properties
else:
return 'absent'
def getClasses(graph):
classes = []
for s,p,o in graph:
if p == VOID.classes:
o = str(o)
classes.append(o)
if len(classes) > 0:
return classes
else:
return 'absent'