senfd 0.2.1__tar.gz → 0.2.3__tar.gz

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.
Files changed (33) hide show
  1. {senfd-0.2.1/src/senfd.egg-info → senfd-0.2.3}/PKG-INFO +1 -1
  2. {senfd-0.2.1 → senfd-0.2.3}/pyproject.toml +1 -1
  3. senfd-0.2.3/src/senfd/__init__.py +1 -0
  4. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/cli.py +1 -4
  5. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/documents/base.py +3 -3
  6. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/documents/enriched.py +11 -6
  7. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/documents/plain.py +11 -9
  8. senfd-0.2.3/src/senfd/errors.py +28 -0
  9. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/pipeline.py +3 -2
  10. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/schemas/enriched.figure.document.schema.json +15 -15
  11. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/schemas/plain.figure.document.schema.json +1 -1
  12. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/tables.py +7 -5
  13. {senfd-0.2.1 → senfd-0.2.3/src/senfd.egg-info}/PKG-INFO +1 -1
  14. senfd-0.2.1/src/senfd/__init__.py +0 -1
  15. senfd-0.2.1/src/senfd/errors.py +0 -30
  16. {senfd-0.2.1 → senfd-0.2.3}/LICENSE +0 -0
  17. {senfd-0.2.1 → senfd-0.2.3}/README.rst +0 -0
  18. {senfd-0.2.1 → senfd-0.2.3}/setup.cfg +0 -0
  19. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/documents/__init__.py +0 -0
  20. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/schemas/__init__.py +0 -0
  21. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/templates/__init__.py +0 -0
  22. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/templates/enriched.figure.document.html.jinja2 +0 -0
  23. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/templates/plain.figure.document.html.jinja2 +0 -0
  24. {senfd-0.2.1 → senfd-0.2.3}/src/senfd/utils.py +0 -0
  25. {senfd-0.2.1 → senfd-0.2.3}/src/senfd.egg-info/SOURCES.txt +0 -0
  26. {senfd-0.2.1 → senfd-0.2.3}/src/senfd.egg-info/dependency_links.txt +0 -0
  27. {senfd-0.2.1 → senfd-0.2.3}/src/senfd.egg-info/entry_points.txt +0 -0
  28. {senfd-0.2.1 → senfd-0.2.3}/src/senfd.egg-info/requires.txt +0 -0
  29. {senfd-0.2.1 → senfd-0.2.3}/src/senfd.egg-info/top_level.txt +0 -0
  30. {senfd-0.2.1 → senfd-0.2.3}/tests/test_case_conversion.py +0 -0
  31. {senfd-0.2.1 → senfd-0.2.3}/tests/test_cli.py +0 -0
  32. {senfd-0.2.1 → senfd-0.2.3}/tests/test_module.py +0 -0
  33. {senfd-0.2.1 → senfd-0.2.3}/tests/test_schema.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: senfd
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Semantic Enhancer for Figure Documents
5
5
  Author-email: "Simon A. F. Lund" <os@safl.dk>
6
6
  License: LGPL-2.1-only
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "senfd"
3
- version = "0.2.1"
3
+ version = "0.2.3"
4
4
  description = "Semantic Enhancer for Figure Documents"
5
5
  authors = [
6
6
  { name = "Simon A. F. Lund", email = "os@safl.dk" }
@@ -0,0 +1 @@
1
+ __version__ = "0.2.3"
@@ -23,10 +23,7 @@ def to_log_file(
23
23
  ) -> Path:
24
24
 
25
25
  content = json.dumps(
26
- [
27
- {"type": type(error).__name__, **senfd.errors.error_to_dict(error)}
28
- for error in errors
29
- ],
26
+ [{"type": type(error).__name__, **error.model_dump()} for error in errors],
30
27
  indent=4,
31
28
  )
32
29
 
@@ -104,7 +104,7 @@ class Document(BaseModel):
104
104
  """Writes the document JSON schema to file at the given 'path'"""
105
105
 
106
106
  return to_file(
107
- json.dumps(cls.schema(), indent=4),
107
+ json.dumps(cls.model_json_schema(), indent=4),
108
108
  cls.schema_filename(),
109
109
  path,
110
110
  )
@@ -141,7 +141,7 @@ class Document(BaseModel):
141
141
  )
142
142
  template = env.get_template(self.FILENAME_HTML_TEMPLATE)
143
143
 
144
- return template.render(document=self.dict())
144
+ return template.render(document=self.model_dump())
145
145
 
146
146
  def to_html_file(self, path: Optional[Path] = None) -> Path:
147
147
  """Writes the document to HTML-formatted file"""
@@ -152,7 +152,7 @@ class Document(BaseModel):
152
152
  """Returns True when validator raises no exceptions, False otherwise"""
153
153
 
154
154
  try:
155
- self.validate(self.dict())
155
+ self.model_validate(self.model_dump())
156
156
  except ValidationError as e:
157
157
  print(e)
158
158
  return False
@@ -24,13 +24,15 @@ class EnrichedFigure(Figure):
24
24
  def from_figure_description(
25
25
  cls, figure: Figure, match
26
26
  ) -> Tuple[Optional[Figure], Optional[NamedTuple]]:
27
- shared = set(figure.dict().keys()).intersection(set(match.groupdict().keys()))
27
+ shared = set(figure.model_dump().keys()).intersection(
28
+ set(match.groupdict().keys())
29
+ )
28
30
  if shared:
29
31
  # This occurs if child attributes overrides parent, this is an error in the
30
32
  # implementation of the child-figure
31
33
  raise RuntimeError(f"cls({cls.__name__}) has overlap({shared})")
32
34
 
33
- data = figure.dict()
35
+ data = figure.model_dump()
34
36
  mdict = match.groupdict()
35
37
  if mdict:
36
38
  data.update(mdict if mdict else {})
@@ -39,6 +41,7 @@ class EnrichedFigure(Figure):
39
41
  # table, errors = senfd.tables.HeaderTable.from_table(figure.table)
40
42
  # data["table"] = table.dict() if table else figure.table.dict()
41
43
  enriched_figure = cls(**data)
44
+ errors = None
42
45
  if figure.table:
43
46
  table, errors = senfd.tables.HeaderTable.from_table(figure.table)
44
47
  enriched_figure.table = table if table else figure.table
@@ -158,7 +161,9 @@ def get_figure_enriching_classes():
158
161
  return [
159
162
  cls
160
163
  for _, cls in inspect.getmembers(senfd.documents.enriched, inspect.isclass)
161
- if issubclass(cls, EnrichedFigure) and hasattr(cls, "REGEX_FIGURE_DESCRIPTION")
164
+ if issubclass(cls, EnrichedFigure)
165
+ and (cls is not senfd.documents.enriched.EnrichedFigure)
166
+ and hasattr(cls, "REGEX_FIGURE_DESCRIPTION")
162
167
  ]
163
168
 
164
169
 
@@ -170,9 +175,6 @@ class EnrichedFigureDocument(Document):
170
175
  FILENAME_SCHEMA: ClassVar[str] = "enriched.figure.document.schema.json"
171
176
  FILENAME_HTML_TEMPLATE: ClassVar[str] = "enriched.figure.document.html.jinja2"
172
177
 
173
- nontabular: List[Figure] = Field(default_factory=list)
174
- uncategorized: List[Figure] = Field(default_factory=list)
175
-
176
178
  acronyms: List[Acronyms] = Field(default_factory=list)
177
179
  io_controller_command_set_support: List[IoControllerCommandSetSupport] = Field(
178
180
  default_factory=list
@@ -198,6 +200,9 @@ class EnrichedFigureDocument(Document):
198
200
  offset: List[Offset] = Field(default_factory=list)
199
201
  property_definition: List[PropertyDefinition] = Field(default_factory=list)
200
202
 
203
+ nontabular: List[Figure] = Field(default_factory=list)
204
+ uncategorized: List[Figure] = Field(default_factory=list)
205
+
201
206
  @classmethod
202
207
  def from_figure_document_file(cls, path: Path):
203
208
  """Instantiate an 'organized' Document from a 'figure' document"""
@@ -107,8 +107,8 @@ class FromDocx(Converter):
107
107
  if not figure:
108
108
  errors.append(
109
109
  senfd.errors.TableCaptionError(
110
- "Does not match figure caption assumptions",
111
- caption,
110
+ message="Does not match figure caption assumptions",
111
+ caption=caption,
112
112
  )
113
113
  )
114
114
  continue
@@ -116,8 +116,8 @@ class FromDocx(Converter):
116
116
  if figure.figure_nr in figures:
117
117
  errors.append(
118
118
  senfd.errors.TableCaptionError(
119
- "Duplicate caption",
120
- caption,
119
+ message="Duplicate caption",
120
+ caption=caption,
121
121
  )
122
122
  )
123
123
  continue
@@ -147,15 +147,17 @@ class FromDocx(Converter):
147
147
  if not figure:
148
148
  errors.append(
149
149
  senfd.errors.TableOfFiguresError(
150
- "Does not match figure assumptions",
151
- caption,
150
+ message="Does not match figure assumptions",
151
+ caption=caption,
152
152
  )
153
153
  )
154
154
  continue
155
155
 
156
156
  if not figure.page_nr:
157
157
  errors.append(
158
- senfd.errors.TableOfFiguresError("Is missing <page_nr>", caption)
158
+ senfd.errors.TableOfFiguresError(
159
+ message="Is missing <page_nr>", caption=caption
160
+ )
159
161
  )
160
162
  continue
161
163
 
@@ -165,8 +167,8 @@ class FromDocx(Converter):
165
167
  if figure.description not in existing.description:
166
168
  errors.append(
167
169
  senfd.errors.TableOfFiguresError(
168
- f"({existing.description}) != {figure.description}",
169
- caption,
170
+ message=f"({existing.description}) != {figure.description}",
171
+ caption=caption,
170
172
  )
171
173
  )
172
174
  else:
@@ -0,0 +1,28 @@
1
+ from typing import Any, List
2
+
3
+ from pydantic import BaseModel
4
+
5
+
6
+ class TableError(BaseModel):
7
+ message: str
8
+
9
+
10
+ class TableOfFiguresError(TableError):
11
+ caption: str
12
+
13
+
14
+ class TableCaptionError(TableError):
15
+ caption: str
16
+
17
+
18
+ class TableHeaderError(TableError):
19
+ caption: str
20
+ cells: List[Any]
21
+
22
+
23
+ class IrregularTableError(TableError):
24
+ lengths: List[int]
25
+
26
+
27
+ class NonTableHeaderError(TableError):
28
+ pass
@@ -1,11 +1,12 @@
1
1
  from pathlib import Path
2
- from typing import List
2
+ from typing import List, Type
3
3
 
4
+ from senfd.documents.base import Converter
4
5
  from senfd.documents.enriched import FromFigureDocument
5
6
  from senfd.documents.plain import FromDocx
6
7
  from senfd.errors import TableError
7
8
 
8
- CONVERTERS = [FromDocx, FromFigureDocument]
9
+ CONVERTERS: List[Type[Converter]] = [FromDocx, FromFigureDocument]
9
10
 
10
11
 
11
12
  def process(input: Path, output: Path) -> List[TableError]:
@@ -497,7 +497,7 @@
497
497
  "DocumentMeta": {
498
498
  "properties": {
499
499
  "version": {
500
- "default": "0.2.1",
500
+ "default": "0.2.3",
501
501
  "title": "Version",
502
502
  "type": "string"
503
503
  },
@@ -915,20 +915,6 @@
915
915
  "meta": {
916
916
  "$ref": "#/$defs/DocumentMeta"
917
917
  },
918
- "nontabular": {
919
- "items": {
920
- "$ref": "#/$defs/Figure"
921
- },
922
- "title": "Nontabular",
923
- "type": "array"
924
- },
925
- "uncategorized": {
926
- "items": {
927
- "$ref": "#/$defs/Figure"
928
- },
929
- "title": "Uncategorized",
930
- "type": "array"
931
- },
932
918
  "acronyms": {
933
919
  "items": {
934
920
  "$ref": "#/$defs/Acronyms"
@@ -1040,6 +1026,20 @@
1040
1026
  },
1041
1027
  "title": "Property Definition",
1042
1028
  "type": "array"
1029
+ },
1030
+ "nontabular": {
1031
+ "items": {
1032
+ "$ref": "#/$defs/Figure"
1033
+ },
1034
+ "title": "Nontabular",
1035
+ "type": "array"
1036
+ },
1037
+ "uncategorized": {
1038
+ "items": {
1039
+ "$ref": "#/$defs/Figure"
1040
+ },
1041
+ "title": "Uncategorized",
1042
+ "type": "array"
1043
1043
  }
1044
1044
  },
1045
1045
  "title": "EnrichedFigureDocument",
@@ -20,7 +20,7 @@
20
20
  "DocumentMeta": {
21
21
  "properties": {
22
22
  "version": {
23
- "default": "0.2.1",
23
+ "default": "0.2.3",
24
24
  "title": "Version",
25
25
  "type": "string"
26
26
  },
@@ -48,11 +48,13 @@ class HeaderTable(Table):
48
48
  lengths = list(set([len(row.cells) for row in table.rows]))
49
49
  if len(lengths) != 1:
50
50
  return None, senfd.errors.IrregularTableError(
51
- f"Varying row lengths({lengths})", lengths
51
+ message=f"Varying row lengths({lengths})", lengths=lengths
52
52
  )
53
53
 
54
54
  if len(table.rows) < 2:
55
- return None, senfd.errors.NonTableHeaderError("Insufficent number of rows")
55
+ return None, senfd.errors.NonTableHeaderError(
56
+ message="Insufficent number of rows"
57
+ )
56
58
 
57
59
  headers = [
58
60
  cell.text.strip()
@@ -61,9 +63,9 @@ class HeaderTable(Table):
61
63
  ]
62
64
  if len(headers) != len(table.rows[1].cells):
63
65
  return None, senfd.errors.TableHeaderError(
64
- "Unsupported names",
65
- table.rows[0].cells[0].text,
66
- [cell.text for cell in table.rows[1].cells],
66
+ message="Unsupported names",
67
+ caption=table.rows[0].cells[0].text,
68
+ cells=[cell.text for cell in table.rows[1].cells],
67
69
  )
68
70
 
69
71
  data = table.dict()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: senfd
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Semantic Enhancer for Figure Documents
5
5
  Author-email: "Simon A. F. Lund" <os@safl.dk>
6
6
  License: LGPL-2.1-only
@@ -1 +0,0 @@
1
- __version__ = "0.2.1"
@@ -1,30 +0,0 @@
1
- from collections import namedtuple
2
- from typing import Any, Dict, List
3
-
4
- from pydantic import BaseModel
5
-
6
- TableOfFiguresError = namedtuple("TableOfFiguresError", ["message", "caption"])
7
-
8
- TableCaptionError = namedtuple("TableCaptionError", ["message", "caption"])
9
-
10
- TableHeaderError = namedtuple("TableHeaderError", ["message", "caption", "cells"])
11
-
12
- IrregularTableError = namedtuple("IrregularTableError", ["message", "lengths"])
13
-
14
- NonTableHeaderError = namedtuple("NonTableHeaderError", ["message"])
15
-
16
- TableError = (
17
- TableOfFiguresError
18
- | TableCaptionError
19
- | TableHeaderError
20
- | IrregularTableError
21
- | NonTableHeaderError
22
- )
23
-
24
-
25
- def error_to_dict(error: TableError) -> Dict[str, List[Any]]:
26
- error_dict = error._asdict()
27
- for key, value in error_dict.items():
28
- if isinstance(value, BaseModel):
29
- error_dict[key] = value.dict()
30
- return error_dict
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes