Skip to content
Snippets Groups Projects

Resolve "Parseur par type d'activité"

1 file
+ 43
2
Compare changes
  • Side-by-side
  • Inline
@@ -183,6 +183,14 @@ class ChoiceGroup:
@@ -183,6 +183,14 @@ class ChoiceGroup:
self.items: list[Choice]
self.items: list[Choice]
 
class Gap:
 
"""A gap in a gap-fill text exercise"""
 
 
def __init__(self, id: str):
 
self.id = id
 
self.choices: list[Choice] = []
 
 
class ExerciceQC(Exercice):
class ExerciceQC(Exercice):
def __init__(self, is_qcm: bool = False) -> None:
def __init__(self, is_qcm: bool = False) -> None:
super().__init__()
super().__init__()
@@ -275,8 +283,41 @@ class ExerciceQM(Exercice):
@@ -275,8 +283,41 @@ class ExerciceQM(Exercice):
class ExerciceTAT(Exercice):
class ExerciceTAT(Exercice):
def __init__(self):
def __init__(self):
super().__init__()
super().__init__()
self.text: str # can be HTML
self.segments: list[str | Gap] = []
self.gaps: list[ChoiceGroup]
 
@override
 
def parse_html(self, root: HtmlElement):
 
super().parse_html(root)
 
# Find the text container
 
try:
 
container = root.find_class("STY_texteTAT")[0]
 
except IndexError as e:
 
raise ParseError("ExerciceTAT: text container not found") from e
 
 
# Text buffer accumulates the text found
 
text_segment_buf = container.text or ""
 
for elem in container:
 
if elem.tag == "select" and "STY_selectTAT" in elem.classes:
 
# It's a gap
 
# Time to "close" the text segment and add it
 
self.segments.append(text_segment_buf)
 
# Add the gap
 
gap_id = elem.attrib["id"].replace("champTrou", "")
 
self.segments.append(Gap(gap_id))
 
# New text segment starts with the tail text of this element
 
text_segment_buf = elem.tail or ""
 
else:
 
text_segment_buf += to_html(elem)
 
 
self.segments.append(text_segment_buf)
 
 
nb_total_gaps = len(container.find_class("STY_selectTAT"))
 
nb_found_gaps = len([e for e in self.segments if isinstance(e, Gap)])
 
if nb_found_gaps != nb_total_gaps:
 
log.warning(
 
f"{self.id}: Text has {nb_total_gaps} gaps in total, but found {nb_found_gaps} gap elements, some might be missing"
 
)
 
pass
class ExerciceGD(Exercice):
class ExerciceGD(Exercice):
Loading