Skip to content

Commit 574c58c

Browse files
committed
Update json format to include formulas
1 parent 29ea36c commit 574c58c

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

grobid_client/format/TEI2LossyJSON.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,8 @@ def _process_div_with_nested_content(self, div: Tag, passage_level: str, head_pa
681681
head_section = None
682682
current_head_paragraph = None
683683

684-
# ------------------------------------------------------------------
685-
# 1. Determine the section header
686-
# ------------------------------------------------------------------
687684
if head:
688-
if not div.find_all("p", recursive=False): # only head, no paragraphs
685+
if not div.find_all("p", recursive=False):
689686
current_head_paragraph = self._clean_text(head.get_text())
690687
else:
691688
head_section = self._clean_text(head.get_text())
@@ -701,23 +698,20 @@ def _process_div_with_nested_content(self, div: Tag, passage_level: str, head_pa
701698
}
702699
head_section = mapping.get(div_type) or div_type.replace("_", " ").title()
703700

704-
# ------------------------------------------------------------------
705-
# 2. Walk the direct children in order
706-
# ------------------------------------------------------------------
707701
paragraph_id = None
708702
for child in div.children:
709703
if not hasattr(child, "name") or not child.name:
710-
continue # skip NavigableString
704+
continue
711705

712-
# ----- nested divs ------------------------------------------------
706+
# nested divs
713707
if child.name in ("div",) or child.name.endswith(":div"):
714708
# recurse – the nested div will use its own header
715709
yield from self._process_div_with_nested_content(
716710
child, passage_level, None
717711
)
718712
continue
719713

720-
# ----- paragraphs -------------------------------------------------
714+
# paragraphs
721715
if child.name == "p":
722716
paragraph_id = get_random_id(prefix="p_")
723717
if passage_level == "sentence":
@@ -737,7 +731,7 @@ def _process_div_with_nested_content(self, div: Tag, passage_level: str, head_pa
737731
)
738732
continue
739733

740-
# ----- formulas ---------------------------------------------------
734+
# formulas
741735
if child.name == "formula":
742736
fid = (
743737
child.get("{http://www.w3.org/XML/1998/namespace}id")
@@ -769,11 +763,8 @@ def _process_div_with_nested_content(self, div: Tag, passage_level: str, head_pa
769763
yield passage
770764
continue
771765

772-
# ------------------------------------------------------------------
773-
# 3. Propagate a possible standalone head for the next div
774-
# ------------------------------------------------------------------
766+
775767
if current_head_paragraph is not None:
776-
# (the caller will receive the updated value via the generator)
777768
pass
778769

779770
def process_directory(self, directory: Union[str, Path], pattern: str = "*.tei.xml", parallel: bool = True, workers: int = None) -> Iterator[Dict]:

0 commit comments

Comments
 (0)