bestroi commited on
Commit
712b847
·
verified ·
1 Parent(s): c23a4ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -11
app.py CHANGED
@@ -551,25 +551,84 @@ with tabs[2]:
551
  # -------------------------------
552
  # Editor Edition Tab
553
  # -------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  with tabs[3]:
555
  st.subheader("Editor Edition")
 
556
  # Select Inscription
557
  inscription_numbers = df['Number'].tolist()
558
  selected_inscription_num = st.selectbox("Select Inscription Number", inscription_numbers, key='editor_select')
559
  selected_inscription = df[df['Number'] == selected_inscription_num].iloc[0]
560
-
 
 
 
561
  # Parse the selected inscription's XML to get the Text element
562
- tree = ET.ElementTree(ET.fromstring(inscriptions_content))
563
- root = tree.getroot()
564
- inscription_elem = root.find(f".//inscription[@n='{selected_inscription_num}']")
565
- text_element = inscription_elem.find("Text") if inscription_elem is not None else None
566
-
567
- if text_element is not None:
568
- editor_text = render_editor(text_element)
569
- st.code(editor_text, language="plaintext")
570
- else:
571
- st.warning("No text found for the selected inscription.")
 
 
572
 
 
 
 
 
 
 
 
 
 
573
  # -------------------------------
574
  # Visualization Tab
575
  # -------------------------------
 
551
  # -------------------------------
552
  # Editor Edition Tab
553
  # -------------------------------
554
+ def render_editor(text_element):
555
+ """
556
+ Processes the Text XML element and converts it to plaintext.
557
+ """
558
+ def process_element(elem):
559
+ result = elem.text if elem.text else ''
560
+
561
+ for child in elem:
562
+ if child.tag == 'lb':
563
+ # Line break; add a newline
564
+ result += '\n'
565
+ elif child.tag == 'expan':
566
+ # Handle expansions, e.g., <expan><abbr>T</abbr><ex>ίτου</ex></expan> → T(ίτου)
567
+ abbr = child.find('abbr')
568
+ ex = child.find('ex')
569
+ if abbr is not None and ex is not None:
570
+ result += f"{abbr.text}({ex.text})"
571
+ else:
572
+ # If structure is unexpected, process children recursively
573
+ result += process_element(child)
574
+ elif child.tag == 'abbr':
575
+ # Abbreviation; add text without special formatting
576
+ result += child.text if child.text else ''
577
+ elif child.tag == 'ex':
578
+ # Expansion; add text within parentheses
579
+ result += f"({child.text})" if child.text else ''
580
+ elif child.tag in ['persName', 'place', 'title']:
581
+ # Names and titles; add text without tags
582
+ # If they contain nested elements, process them
583
+ result += process_element(child)
584
+ else:
585
+ # For any other tags, process their children
586
+ result += process_element(child)
587
+
588
+ if child.tail:
589
+ result += child.tail
590
+
591
+ return result
592
+
593
+ return process_element(text_element).strip()
594
+
595
+ # Assuming 'df' is your DataFrame and 'inscriptions_content' is defined appropriately
596
+ # Here's the updated 'with tabs[3]:' block:
597
+
598
  with tabs[3]:
599
  st.subheader("Editor Edition")
600
+
601
  # Select Inscription
602
  inscription_numbers = df['Number'].tolist()
603
  selected_inscription_num = st.selectbox("Select Inscription Number", inscription_numbers, key='editor_select')
604
  selected_inscription = df[df['Number'] == selected_inscription_num].iloc[0]
605
+
606
+ # Assuming 'Content' column contains the XML string for each inscription
607
+ inscriptions_content = selected_inscription['Content']
608
+
609
  # Parse the selected inscription's XML to get the Text element
610
+ try:
611
+ tree = ET.ElementTree(ET.fromstring(inscriptions_content))
612
+ root = tree.getroot()
613
+
614
+ # Locate the inscription element with the matching number
615
+ inscription_elem = root.find(f".//inscription[@n='{selected_inscription_num}']")
616
+
617
+ # If the root itself is the inscription
618
+ if inscription_elem is None and root.tag == 'inscription' and root.attrib.get('n') == str(selected_inscription_num):
619
+ inscription_elem = root
620
+
621
+ text_element = inscription_elem.find("Text") if inscription_elem is not None else None
622
 
623
+ if text_element is not None:
624
+ editor_text = render_editor(text_element)
625
+ st.code(editor_text, language="plaintext")
626
+ else:
627
+ st.warning("No text found for the selected inscription.")
628
+ except ET.ParseError as e:
629
+ st.error(f"Error parsing XML: {e}")
630
+ except Exception as e:
631
+ st.error(f"An unexpected error occurred: {e}")
632
  # -------------------------------
633
  # Visualization Tab
634
  # -------------------------------