-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_validity_checker.py
150 lines (130 loc) · 5.71 KB
/
func_validity_checker.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
import func_helper as helper
class WarningList:
def __init__(self):
self.warning = []
self.error = []
self.missing_fields = []
def add_error(self, error):
self.error.append(error)
def add_warning(self, warning):
self.warning.append(warning)
def add_missing_field(self, warning):
self.missing_fields.append(warning)
def print_error(self):
for idx, x in enumerate(self.error):
print(str(idx+1) + " " + x)
def print_warning(self):
for idx, x in enumerate(self.warning):
print(str(idx+1)+" "+x)
def print_missing_fields(self):
for idx, x in enumerate(self.missing_fields):
print(str(idx+1) + " " + x)
def print_msg(self):
print("There are "+str(len(self.error))+" error(s), "+str(len(self.warning))+" warning(s), and " +
str(len(self.missing_fields))+" empty field(s).")
class Headerlist:
def __init__(self):
self.header_modified = []
self.header_original = []
def add_header(self, real_header):
for header in real_header:
if header.lower() not in self.header_modified:
self.header_modified.append(header.lower())
def check_header(self, warning_list, real_header):
error = []
warning = []
spelling = []
if 'identifier' not in self.header_modified and 'id' not in self.header_modified:
error.append('identifier')
self.header_modified.append('identifier')
elif 'id' in self.header_modified:
spelling.append('identifier')
for header in real_header:
if (header.lower() not in self.header_modified) and (
header.lower() == 'identifier' or header.lower() == 'title' or header.lower() == 'type'):
error.append(header)
elif header.lower() not in self.header_modified:
warning.append(header)
elif header.strip() not in self.header_original:
spelling.append(header)
if error:
text = helper.print_fields(error)
warning_list.add_error("ERROR: Missing column(s): "+text)
if warning:
text = helper.print_fields(warning)
warning_list.add_warning("Warning: Missing column(s): "+text)
if spelling:
text = helper.print_fields(spelling)
warning_list.add_warning("Warning: Check spelling: "+text)
class Atomic:
def __init__(self, identifier, title, description, url, oer_type, assesses, comesAfter, alternativeContent, requires,
isPartOf, isFormatOf):
self.identifier = identifier
self.title = title
self.description = description
self.url = url
self.oer_type = oer_type
self.assesses = assesses
self.comesAfter = comesAfter
self.alternativeContent = alternativeContent
self.requires = requires
self.isPartOf = isPartOf
self.isFormatOf = isFormatOf
def confirm_fields(self, warning_list):
list_error = []
list_warning = []
type_warning = []
if self.identifier is not None:
if len(self.identifier) == 0:
list_error.append('identifier')
elif not self.identifier.isalnum():
type_warning.append('identifier [type:alphanumeric]')
if self.title is not None:
if len(self.title) == 0:
list_error.append('title')
elif type(self.title) != str:
type_warning.append('title [type:integer]')
if self.oer_type is not None:
if len(self.oer_type) == 0:
list_error.append('type')
if self.description is not None:
if len(self.description) == 0:
list_warning.append('description')
if self.url is not None:
if len(self.url) == 0:
list_warning.append('url')
if self.assesses is not None:
if len(self.assesses) == 0:
list_warning.append('assesses')
elif not self.assesses.isdigit():
type_warning.append('assesses [type:integer]')
if len(self.assesses) != 0 and self.oer_type == 'iER':
type_warning.append('iER should not have an assess property')
elif len(self.assesses) != 0 and self.oer_type == 'aER':
type_warning.append('aER should not have an assess property')
if self.comesAfter is not None:
if len(self.comesAfter) == 0:
list_warning.append('comesAfter')
if self.alternativeContent is not None:
if len(self.alternativeContent) == 0:
list_warning.append('alternativeContent')
if self.requires is not None:
if len(self.requires) == 0:
list_warning.append('requires')
if self.isPartOf is not None:
if len(self.isPartOf) == 0:
list_warning.append('isPartOf')
if self.isFormatOf is not None:
if len(self.isFormatOf) == 0:
list_warning.append('isFormatOf')
error = helper.print_fields(list_error)
warning = helper.print_fields(list_warning)
type_warnings = helper.print_fields(type_warning)
if error:
warning_list.add_error("ERROR: Missing the following field(s): " + error + " on row ID: "+self.identifier)
if warning:
warning_list.add_missing_field("The following field(s) are empty: " + warning + " on row ID: "+self.identifier)
if type_warnings:
warning_list.add_error("The following field(s) have an incorrect type: " + type_warnings + " on row ID: "+self.identifier)
class Composite(Atomic):
pass