prefig 0.4.6.dev20250926053320__py3-none-any.whl → 0.4.6.dev20250928053207__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import lxml.etree as ET
2
2
  import logging
3
+ import copy
3
4
 
4
5
  log = logging.getLogger('prefigure')
5
6
 
@@ -122,3 +123,109 @@ def annotate(element, diagram, parent = None):
122
123
  ACTIVE = ET.Element('ACTIVE')
123
124
  ACTIVE.text = element.get('id')
124
125
  sonification.append(ACTIVE)
126
+
127
+ pronounciations = {
128
+ 'de-solve': 'D E solve',
129
+ 'define-shapes': 'define shapes',
130
+ 'angle-marker': 'angle marker',
131
+ 'area-between-curves': 'area between curves',
132
+ 'area-under-curve': 'area under curve',
133
+ 'grid-axes': 'grid axes',
134
+ 'implicit-curve': 'implicit curve',
135
+ 'parametric-curve': 'parametric curve',
136
+ 'plot-de-solution': 'plot D E solution',
137
+ 'riemann-sum': 'Riemann sum',
138
+ 'slope-field': 'slope field',
139
+ 'tick-mark': 'tick mark',
140
+ 'tangent-line': 'tangent line',
141
+ 'vector-field': 'vector field'
142
+ }
143
+
144
+ labeled_elements = {
145
+ 'label',
146
+ 'point',
147
+ 'xlabel',
148
+ 'ylabel',
149
+ 'angle-marker',
150
+ 'tick-mark',
151
+ 'item',
152
+ 'node',
153
+ 'edge'
154
+ }
155
+
156
+ label_subelements = {
157
+ 'm': 'math',
158
+ 'b': 'bold',
159
+ 'it': 'italics',
160
+ 'plain': 'plain',
161
+ 'newline': 'new line'
162
+ }
163
+
164
+ def diagram_to_speech(diagram):
165
+ diagram = copy.deepcopy(diagram)
166
+
167
+ element_num = 0
168
+ for element in diagram.getiterator():
169
+ if element.tag in label_subelements.keys():
170
+ element.getparent().remove(element)
171
+ continue
172
+ attribs = copy.deepcopy(element.attrib)
173
+ for attrib_name in list(element.attrib.keys()):
174
+ element.attrib.pop(attrib_name)
175
+
176
+ if element.tag == "diagram":
177
+ element.set('ref', 'figure')
178
+ intro = "This prefigure source file begins with a diagram having these attributes: "
179
+ elif element.tag == "definition":
180
+ element.set('ref', 'element-'+str(element_num))
181
+ tag_speech = 'definition'
182
+ intro = "A definition element defining " + element.text.strip()
183
+ elif element.tag in labeled_elements:
184
+ element.set('ref', 'element-'+str(element_num))
185
+ tag_speech = pronounciations.get(element.tag, element.tag)
186
+ label_text = label_to_speech(element)
187
+ if len(label_text) > 0:
188
+ if len(attribs) == 0:
189
+ intro = f"A {tag_speech} element with label {label_text}. The element has no attributes."
190
+ else:
191
+ intro = f"A {tag_speech} element with label {label_text}. There are these attributes: "
192
+ else:
193
+ if len(attribs) == 0:
194
+ intro = f"A {tag_speech} element with no attributes."
195
+ else:
196
+ intro = f"A {tag_speech} element with these attributes: "
197
+ element.text = None
198
+ else:
199
+ element.set('ref', 'element-'+str(element_num))
200
+ tag_speech = pronounciations.get(element.tag, element.tag)
201
+ if len(attribs) == 0:
202
+ intro = f"A {tag_speech} element with no attributes"
203
+ else:
204
+ intro = f"A {tag_speech} element with these attributes: "
205
+ element.set("text", intro + attributes_to_speech(attribs))
206
+ element_num += 1
207
+ element.tag = "annotation"
208
+
209
+ log.error(ET.tostring(diagram, pretty_print=True))
210
+ return diagram
211
+
212
+ def attributes_to_speech(attribs):
213
+ strings = []
214
+ for key, value in attribs.items():
215
+ strings.append(f"{key} has value {value}")
216
+ return ', '.join(strings)
217
+
218
+ def label_to_speech(element):
219
+ strings = []
220
+ if (element.text is not None and
221
+ len(element.text.strip()) > 0):
222
+ strings.append(element.text.strip())
223
+ for child in element:
224
+ child_speech = label_subelements.get(child.tag, child.tag)
225
+ strings.append('begin ' + child_speech)
226
+ strings.append(child.text.strip())
227
+ strings.append('end ' + child_speech)
228
+ if (child.tail is not None and
229
+ child.tail.strip() is not None):
230
+ strings.append(child.tail.strip())
231
+ return ' '.join(strings)
prefig/core/diagram.py CHANGED
@@ -9,6 +9,7 @@ from . import utilities as util
9
9
  from . import CTM
10
10
  from . import label
11
11
  from . import math_utilities as math_util
12
+ from . import annotations
12
13
 
13
14
  log = logging.getLogger('prefigure')
14
15
 
@@ -31,6 +32,16 @@ class Diagram:
31
32
  self.environment = environment
32
33
  self.caption = ""
33
34
 
35
+ self.add_default_annotations = True
36
+ if (self.environment == 'pyodide' and
37
+ len(self.diagram_element.xpath('.//annotations')) == 0
38
+ ):
39
+ diagram_annotations = annotations.diagram_to_speech(diagram_element)
40
+ annotations_tree = ET.SubElement(self.diagram_element,
41
+ 'annotations')
42
+ annotations_tree.append(diagram_annotations)
43
+ self.add_default_annotations = False
44
+
34
45
  math_util.set_diagram(self)
35
46
 
36
47
  label.init(self.format, self.environment)
@@ -582,6 +593,8 @@ class Diagram:
582
593
  self.annotations_root = ET.Element('annotations')
583
594
 
584
595
  def add_default_annotation(self, annotation):
596
+ if not self.add_default_annotations:
597
+ return
585
598
  self.default_annotations.append(annotation)
586
599
 
587
600
  def get_default_annotations(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prefig
3
- Version: 0.4.6.dev20250926053320
3
+ Version: 0.4.6.dev20250928053207
4
4
  Summary: An authoring system for mathematical diagrams
5
5
  Home-page: https://prefigure.org
6
6
  License: GPL-3.0-or-later
@@ -2,7 +2,7 @@ prefig/__init__.py,sha256=tAf78JkO5kBvFM23RmchK8TEDYO6v8AXqzOv-kq7TR0,53
2
2
  prefig/cli.py,sha256=-jbXTVb2Vao4uefq3ia69DDh7ZQivIO-H1grzCVPg0I,12495
3
3
  prefig/core/CTM.py,sha256=P32b5rfJD_8QwMNCHRAS6lIB5ellBi1gaSdhxTV4a00,5781
4
4
  prefig/core/__init__.py,sha256=roT0a8-iBrp8WXTbPN5RzMWFiCXfpKrEXa2xE-F-yBo,728
5
- prefig/core/annotations.py,sha256=9wStnLhEHFmkIocufHLiBcUZ3NSce7ZESor5kjj-vzg,3998
5
+ prefig/core/annotations.py,sha256=YYt7xVVVTbsuxGx7cSaW7KMMDa52STLEhTwAlDkBfoA,7710
6
6
  prefig/core/area.py,sha256=U-AxXvaZJWgVccpLlh-aaRfM_QtTa09NR2TqAd8Yk0o,3710
7
7
  prefig/core/arrow.py,sha256=h8lFm1rMdpiZRyQu5kvAiptBmMYr5aKCZuB5JypAGDM,11283
8
8
  prefig/core/axes.py,sha256=3J6eWNXRWTlbFVNfWkv_-Hyq4L7UP54EQ5u1r82Cfy0,31830
@@ -12,7 +12,7 @@ prefig/core/clip.py,sha256=X3TcFYPuZwjZ9SFBWMc1MYY__6XTJqLafPeOLFNOdIE,806
12
12
  prefig/core/compat.py,sha256=_dI4aGtDrfhcw33r1SQS6kMwwgJj8dJ2A2GcLmtwX7o,729
13
13
  prefig/core/coordinates.py,sha256=vEAJ8kL9S1VylxWysqY5qW2WyCMyHj42yFkuAzjfqFs,3518
14
14
  prefig/core/definition.py,sha256=7LiaCxQwwEPdcnMpcMgrkZEfAoTc5ng8LO6Nf50Htwg,1033
15
- prefig/core/diagram.py,sha256=-8zjo6FgDs74OLMkd3rgncBHrEue3S86hwQ3ISh-nj4,23253
15
+ prefig/core/diagram.py,sha256=ncCTt61xmtEo9J9NP0pk0tZbfHCgN2lW-palUsfEVAs,23830
16
16
  prefig/core/diffeqs.py,sha256=aLXcmTsnfTG6L2-RiNfSaijzwmJF6xJcQpNQdDAWTQo,7127
17
17
  prefig/core/graph.py,sha256=q81dyJy3CxMWvMNhm74SZ9yjfltatdckmajxegA0z0A,10064
18
18
  prefig/core/grid_axes.py,sha256=v98C5tb9knNViGYGDrWL_ULb7Y78vMSQ6OJO7Xd0DXY,12165
@@ -61,8 +61,8 @@ prefig/resources/schema/pf_schema.rng,sha256=SmYGLT9X6w6LEWulHHz2RgD6Q2v1sV24Wjc
61
61
  prefig/resources/template/pf_publication.xml,sha256=eEv8HACv610Apw5DSVNy0reLfELYqHlNy9Oq0GH7C_c,200
62
62
  prefig/scripts/__init__.py,sha256=qJcPi1WRh9UAwu4zIFJbmxWalAMilMYqgi6LxRkF7bI,25
63
63
  prefig/scripts/install_mj.py,sha256=5A6-oc1xbIXka5mkFE70vlp9-Rh_QoxOxGMrQi9Hkio,1219
64
- prefig-0.4.6.dev20250926053320.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
65
- prefig-0.4.6.dev20250926053320.dist-info/METADATA,sha256=RgRq4-AY-jczI_Oerm5z1n8rGbJjGypR3ed90pJTwz8,8716
66
- prefig-0.4.6.dev20250926053320.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
67
- prefig-0.4.6.dev20250926053320.dist-info/entry_points.txt,sha256=OP4ZQT71q2b0Zfbie-oM2Z1HlxpkuX7qaxJnzwsBOVQ,42
68
- prefig-0.4.6.dev20250926053320.dist-info/RECORD,,
64
+ prefig-0.4.6.dev20250928053207.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
65
+ prefig-0.4.6.dev20250928053207.dist-info/METADATA,sha256=gAGpzI4DznW_MCRQXQubi3n9L1iOrNBc4FB6zorBrOM,8716
66
+ prefig-0.4.6.dev20250928053207.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
67
+ prefig-0.4.6.dev20250928053207.dist-info/entry_points.txt,sha256=OP4ZQT71q2b0Zfbie-oM2Z1HlxpkuX7qaxJnzwsBOVQ,42
68
+ prefig-0.4.6.dev20250928053207.dist-info/RECORD,,