eduagarcia
commited on
Commit
•
fe81053
1
Parent(s):
b265980
Update: remove nullified questions
Browse files- oab_exams_disabled.py +13 -3
oab_exams_disabled.py
CHANGED
@@ -56,10 +56,12 @@ FILES = [
|
|
56 |
def join_lines(lines):
|
57 |
texts = []
|
58 |
for line in lines:
|
59 |
-
if line.strip() == "":
|
60 |
texts.append("\n")
|
61 |
else:
|
62 |
-
texts
|
|
|
|
|
63 |
return "".join(texts).strip()
|
64 |
|
65 |
class OABExams(datasets.GeneratorBasedBuilder):
|
@@ -75,6 +77,7 @@ class OABExams(datasets.GeneratorBasedBuilder):
|
|
75 |
"exam_id": datasets.Value("string"),
|
76 |
"exam_year": datasets.Value("string"),
|
77 |
"question_type": datasets.Value("string"),
|
|
|
78 |
"question": datasets.Value("string"),
|
79 |
"choices": datasets.Sequence(feature={
|
80 |
"text": datasets.Value("string"),
|
@@ -110,6 +113,7 @@ class OABExams(datasets.GeneratorBasedBuilder):
|
|
110 |
for i, line in enumerate(lines):
|
111 |
# if line matches regex that validates "Questão 1" or "Questão 80 NULL"
|
112 |
if re.match(r"Questão \d{1,2}(\sNULL)?", line.strip()):
|
|
|
113 |
question_number = int(line.strip().split(" ")[1])
|
114 |
question_id = exam_id + "_" + str(question_number)
|
115 |
questions_temp.append(
|
@@ -118,7 +122,8 @@ class OABExams(datasets.GeneratorBasedBuilder):
|
|
118 |
"question_number": question_number,
|
119 |
"exam_id": exam_id,
|
120 |
"exam_year": exam_year,
|
121 |
-
"lines": [line]
|
|
|
122 |
}
|
123 |
)
|
124 |
else:
|
@@ -167,12 +172,17 @@ class OABExams(datasets.GeneratorBasedBuilder):
|
|
167 |
choices["text"].append(join_lines(temp_question_text))
|
168 |
temp_question_text = None
|
169 |
|
|
|
|
|
|
|
|
|
170 |
yield question_temp['question_id'], {
|
171 |
"id": question_temp['question_id'],
|
172 |
"question_number": question_temp['question_number'],
|
173 |
"exam_id": question_temp['exam_id'],
|
174 |
"exam_year": question_temp['exam_year'],
|
175 |
"question_type": question_type,
|
|
|
176 |
"question": question,
|
177 |
"choices": choices,
|
178 |
"answerKey": answerKey
|
|
|
56 |
def join_lines(lines):
|
57 |
texts = []
|
58 |
for line in lines:
|
59 |
+
if line.strip() == "" and len(texts) > 0 and texts[-1] != "\n":
|
60 |
texts.append("\n")
|
61 |
else:
|
62 |
+
if len(texts) > 0 and texts[-1] != "\n":
|
63 |
+
texts.append(" ")
|
64 |
+
texts.append(line.strip())
|
65 |
return "".join(texts).strip()
|
66 |
|
67 |
class OABExams(datasets.GeneratorBasedBuilder):
|
|
|
77 |
"exam_id": datasets.Value("string"),
|
78 |
"exam_year": datasets.Value("string"),
|
79 |
"question_type": datasets.Value("string"),
|
80 |
+
"nullified": datasets.Value("bool"),
|
81 |
"question": datasets.Value("string"),
|
82 |
"choices": datasets.Sequence(feature={
|
83 |
"text": datasets.Value("string"),
|
|
|
113 |
for i, line in enumerate(lines):
|
114 |
# if line matches regex that validates "Questão 1" or "Questão 80 NULL"
|
115 |
if re.match(r"Questão \d{1,2}(\sNULL)?", line.strip()):
|
116 |
+
nullified = 'NULL' in line
|
117 |
question_number = int(line.strip().split(" ")[1])
|
118 |
question_id = exam_id + "_" + str(question_number)
|
119 |
questions_temp.append(
|
|
|
122 |
"question_number": question_number,
|
123 |
"exam_id": exam_id,
|
124 |
"exam_year": exam_year,
|
125 |
+
"lines": [line],
|
126 |
+
"nullified": nullified
|
127 |
}
|
128 |
)
|
129 |
else:
|
|
|
172 |
choices["text"].append(join_lines(temp_question_text))
|
173 |
temp_question_text = None
|
174 |
|
175 |
+
#Remove nulls
|
176 |
+
if question_temp["nullified"]:
|
177 |
+
continue
|
178 |
+
|
179 |
yield question_temp['question_id'], {
|
180 |
"id": question_temp['question_id'],
|
181 |
"question_number": question_temp['question_number'],
|
182 |
"exam_id": question_temp['exam_id'],
|
183 |
"exam_year": question_temp['exam_year'],
|
184 |
"question_type": question_type,
|
185 |
+
"nullified": question_temp['nullified'],
|
186 |
"question": question,
|
187 |
"choices": choices,
|
188 |
"answerKey": answerKey
|