MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / parse_poster_xml

Function parse_poster_xml

PosterAgent/tree_split_layout.py:15–90  ·  view source on GitHub ↗

Parse an XML describing a single poster layout, e.g.: Introduction ... </P

(xml_file)

Source from the content-addressed store, hash-verified

13 return tree.getroot()
14
15def parse_poster_xml(xml_file):
16 """
17 Parse an XML describing a single poster layout, e.g.:
18
19 <Poster Width="685" Height="968">
20 <Panel left="5" right="160" width="674" height="123">
21 <Text>Introduction</Text>
22 <Figure left="567" right="178" width="81" height="99" no="1" ... />
23 </Panel>
24 ...
25 </Poster>
26
27 Returns a dict with:
28 {
29 'poster_width': float,
30 'poster_height': float,
31 'panels': [
32 {
33 'x': float,
34 'y': float,
35 'width': float,
36 'height': float,
37 'text_blocks': [string, string, ...],
38 'figure_blocks': [(fx, fy, fw, fh), ...]
39 },
40 ...
41 ]
42 }
43 """
44 root = parse_xml_with_recovery(xml_file)
45
46 # Poster dimensions
47 poster_w = float(root.get("Width", "1"))
48 poster_h = float(root.get("Height", "1"))
49
50 panels_data = []
51
52 # Iterate <Panel> elements
53 for panel_node in root.findall("Panel"):
54 x = float(panel_node.get("left", "0"))
55 y = float(panel_node.get("right", "0"))
56 w = float(panel_node.get("width", "0"))
57 h = float(panel_node.get("height", "0"))
58
59 # Gather text blocks
60 text_blocks = []
61 for text_node in panel_node.findall("Text"):
62 txt = text_node.text or ""
63 txt = txt.strip()
64 if txt:
65 text_blocks.append(txt)
66
67 # Gather figure blocks
68 figure_blocks = []
69 for fig_node in panel_node.findall("Figure"):
70 fx = float(fig_node.get("left", "0"))
71 fy = float(fig_node.get("right", "0"))
72 fw = float(fig_node.get("width", "0"))

Callers 1

main_trainFunction · 0.70

Calls 1

parse_xml_with_recoveryFunction · 0.70

Tested by

no test coverage detected