Three perspectives on My Dog
+View A: From the Front, Laughing
View B: From the Side, Best Profile
View C: In Motion, A Blur on Feet
diff --git a/packtools/sps/models/figures.py b/packtools/sps/models/figures.py
new file mode 100644
index 000000000..038899c7a
--- /dev/null
+++ b/packtools/sps/models/figures.py
@@ -0,0 +1,72 @@
+from packtools.sps.utils import xml_utils
+
+
+def get_node_without_subtag(node):
+ """
+ Função que retorna nó sem subtags.
+ """
+ return "".join(node.xpath(".//text()"))
+
+
+class Figure:
+ def __init__(self, xmltree):
+ self.xmltree = xmltree
+
+
+ def extract_figures(self, subtag):
+ fig_node = self.xmltree.xpath('.//fig-group') or self.xmltree.xpath('.//fig')
+ extract_node_text = xml_utils.node_text_without_xref if subtag else get_node_without_subtag
+
+ if fig_node:
+ if self.xmltree.xpath('.//fig-group'):
+ return self._extract_figures_with_fig_group(node=fig_node, extract_node_text=extract_node_text)
+ else:
+ return self._extract_figures_without_fig_group(node=fig_node, extract_node_text=extract_node_text)
+ else:
+ return 'No figures found.'
+
+
+ def _extract_figures_with_fig_group(self, node, extract_node_text):
+ figures = []
+
+ for fig_group_node in node:
+ fig_group_id = fig_group_node.get('id', '')
+
+ try:
+ fig_group_title = extract_node_text(fig_group_node.xpath('.//title')[0])
+ except IndexError:
+ fig_group_title = ''
+
+ fig_group = {'fig_group_id': fig_group_id, 'fig_group_title': fig_group_title}
+
+ data = self._extract_figures_without_fig_group(node=fig_group_node.xpath('fig'), extract_node_text=extract_node_text)
+ fig_group.update(data)
+
+ figures.append(fig_group)
+ return figures
+
+
+ def _extract_figures_without_fig_group(self, node, extract_node_text):
+ figures = {'figs': []}
+ data_fig = ['label', 'title']
+
+ for fig in node:
+ fig_id = fig.get('id', '')
+ data = {'id': fig_id}
+
+ for field in data_fig:
+ try:
+ data[field] = extract_node_text(fig.xpath(f'.//{field}')[0])
+ except IndexError:
+ data[field] = ''
+
+ try:
+ fig_graphic = fig.xpath('graphic')[0].get('{http://www.w3.org/1999/xlink}href')
+ except IndexError:
+ fig_graphic = ''
+
+ data['graphic'] = fig_graphic
+ figures['figs'].append(data)
+ return figures
+
+
\ No newline at end of file
diff --git a/packtools/sps/models/formula.py b/packtools/sps/models/formula.py
new file mode 100644
index 000000000..83534dcb1
--- /dev/null
+++ b/packtools/sps/models/formula.py
@@ -0,0 +1,53 @@
+from packtools.sps.utils import xml_utils
+
+class Formula:
+ def __init__(self, xmltree):
+ self.xmltree = xmltree
+
+
+ @property
+ def disp_formula_nodes(self):
+ return self.xmltree.xpath('.//disp-formula')
+
+
+ def get_equation(self, node):
+ mnl_namespace = {'mnl': "http://www.w3.org/1998/Math/MathML"}
+ math_node_xpath = 'mnl:math'
+ tex_math_xpath = 'tex-math'
+ graphic_xpath = 'graphic'
+
+ if node.xpath(math_node_xpath, namespaces=mnl_namespace) or node.xpath(tex_math_xpath):
+ eq_node = node.xpath(math_node_xpath, namespaces=mnl_namespace) or node.xpath(tex_math_xpath)
+ eq_node_id = eq_node[0].get('id', '')
+ eq = xml_utils.node_text_without_xref(eq_node[0])
+ eq_dict = {'id': eq_node_id, 'equation': eq}
+ return eq_dict
+ elif node.xpath(graphic_xpath):
+ eq_node = node.xpath(graphic_xpath)[0]
+ eq_node_id = eq_node.get('id', '')
+ eq_graphic = eq_node.get('{http://www.w3.org/1999/xlink}href')
+ eq_dict = {'id': eq_node_id, 'graphic': eq_graphic}
+ return eq_dict
+ return 'Not found formulas'
+
+
+ @property
+ def extract_disp_formula(self):
+ node = self.disp_formula_nodes
+ formulas = {'formulas': []}
+ for disp_node in node:
+ disp_node_id = disp_node.get('id', '')
+
+ try:
+ disp_node_label = disp_node.xpath('label')[0].text
+ except IndexError:
+ disp_node_label = ''
+ equation = self.get_equation(node=disp_node)
+
+ formula = {
+ 'disp_formula_id': disp_node_id,
+ 'disp_formula_label': disp_node_label,
+ 'equations': equation
+ }
+ formulas['formulas'].append(formula)
+ return formulas
\ No newline at end of file
diff --git a/packtools/sps/models/tables.py b/packtools/sps/models/tables.py
new file mode 100644
index 000000000..93821aa57
--- /dev/null
+++ b/packtools/sps/models/tables.py
@@ -0,0 +1,73 @@
+from packtools.sps.utils import xml_utils
+
+
+def get_node_without_subtag(node):
+ """
+ Função que retorna nó sem subtags.
+ """
+ return "".join(node.xpath(".//text()"))
+
+
+class Table:
+ def __init__(self, xmltree):
+ self.xmltree = xmltree
+
+
+ def extract_table(self, subtag):
+ table_node = self.xmltree.xpath('.//table-wrap-group') or self.xmltree.xpath('.//table-wrap')
+ extract_node_text = xml_utils.node_text_without_xref if subtag else get_node_without_subtag
+
+ if table_node:
+ if self.xmltree.xpath('.//table-wrap-group'):
+ return self._extract_table_with_table_wrap_group(node=table_node, extract_node_text=extract_node_text)
+ else:
+ return self._extract_table_without_table_wrap_group(node=table_node, extract_node_text=extract_node_text)
+ else:
+ return 'No tables found.'
+
+
+ def _extract_table_with_table_wrap_group(self, node, extract_node_text):
+ tables = []
+
+ for table_node in node:
+ table_group_id = table_node.get('id', '')
+ table_group = {'table_group_id': table_group_id}
+ data = self._extract_table_without_table_wrap_group(node=table_node.xpath('.//table-wrap'), extract_node_text=extract_node_text)
+ table_group.update(data)
+ tables.append(table_group)
+ return tables
+
+
+ def _extract_table_without_table_wrap_group(self, node, extract_node_text):
+ tables = {'tables': []}
+ data_tables = ['label', 'title']
+
+ for table_node in node:
+ table_id = table_node.get('id', '')
+ data = {'id': table_id}
+
+ for field in data_tables:
+ try:
+ data[field] = extract_node_text(table_node.xpath(f'.//{field}')[0])
+ except IndexError:
+ data[field] = ''
+
+ try:
+ data['table'] = xml_utils.node_text_without_xref(table_node.xpath('table')[0])
+ except IndexError:
+ data['table'] = ''
+
+ foot = self.extract_table_wrap_foot(node=table_node, extract_node_text=extract_node_text)
+
+ data.update(foot)
+ tables['tables'].append(data)
+ return tables
+
+
+ def extract_table_wrap_foot(self, node, extract_node_text):
+ try:
+ foot = extract_node_text(node.xpath('table-wrap-foot')[0])
+ except IndexError:
+ foot = ''
+ foot = {'wrap-foot': foot}
+ return foot
\ No newline at end of file
diff --git a/tests/sps/test_figure.py b/tests/sps/test_figure.py
new file mode 100644
index 000000000..4c39fdce7
--- /dev/null
+++ b/tests/sps/test_figure.py
@@ -0,0 +1,181 @@
+from unittest import TestCase
+from packtools.sps.utils import xml_utils
+
+
+from packtools.sps.models.figures import Figure
+
+from lxml import etree
+
+
+class FiguresTest(TestCase):
+ def test_extract_with_fig_group(self):
+ xml = ("""
+ Three perspectives on My Dog View A: From the Front, Laughing View B: From the Side, Best Profile View C: In Motion, A Blur on Feet Three perspectives on My Dog View A: From the Front, Laughing View B: From the Side, Best Profile View C: In
View A: From the Front, Laughing
', + 'label': 'a.', + 'graphic': 'frontView.png' + }, + { + 'id': 'fg-13', + 'title': 'View B: From the Side, Best Profile
', + 'label': 'b.', + 'graphic': 'sideView.png' + }, + { + 'id': 'fg-14', + 'title': 'View C: In
Item | +% Correct response | +Difficulty ( |
+ Discrimination ( |
+
---|---|---|---|
1. The risk of transmitting HIV is small if one follows the treatment correctly. | +35.5 | +14.45 | +0.04 | +
2. People are using less condoms because of AIDS treatment. | +34.5 | +14.23 | +0.04 | +
3. A person can get the AIDS virus by using public toilets. | +78.1 | +3.72 | +0.95 | +
4. A person can get the AIDS virus through insect bites. | +75.5 | +3.70 | +0.72 | +
5. A person can become infected by sharing eating utensils, cups or food. | +85.7 | +3.28 | +1.01 | +
6. The risk of HIV + mothers infecting their babies is small if she receives treatment in pregnancy and childbirth. | +75.8 | +2.70 | +0.32 | +
7. The risk of HIV infection can be reduced if you have relations only with an uninfected partner. | +72.6 | +2.03 | +0.20 | +
8. A healthy person can be infected with the AIDS virus. | +94.1 | +1.61 | +0.59 | +
9. A person can get the virus from sharing a syringe or needle. | +96.9 | +1.51 | +0.78 | +
10. Anyone can get the AIDS virus if condoms are not used. | +98.5 | +1.27 | +0.95 | +
+
Proposta de Novas Tabelas - 2016 | +||
---|---|---|
Receita Bruta em 12 Meses - em R$ | +Anexo I - Comércio | +Anexo II Indústria | +
De R$ 225.000,01 a RS 450.000,00 | +4,00% | +4,50% | +
De R$ 450.000,01 a R$ 900.000,00 | +8,25% | +8,00% | +
De R$ 900.000,01 a R$ 1.800.000,00 | +11,25% | +12,25% | +
A informação de alíquota do anexo II é significativa
+