Skip to content

Commit f88421e

Browse files
author
Robert Sachunsky
committed
patch ocrd_page_generateds for automatic inheritance
1 parent 881020d commit f88421e

File tree

3 files changed

+195
-18
lines changed

3 files changed

+195
-18
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ generate-page: repo/assets
100100
sed -i 's/_nsprefix_ = None/_nsprefix_ = "pc"/' $(GDS_PAGE)
101101
# hack to ensure child nodes also have pc: prefix...
102102
sed -i 's/.*_nsprefix_ = child_.prefix$$//' $(GDS_PAGE)
103+
# hack to get #698: auto-inheritance of attributes and TextStyle
104+
patch -p1 < ocrd_models/ocrd_page_generateds.build.inherited.patch
103105

104106
#
105107
# Repos

ocrd_models/ocrd_models/ocrd_page_generateds.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from six.moves import zip_longest
2828
import os
2929
import sys
30+
import copy
3031
import re as re_
3132
import base64
3233
import datetime as datetime_
@@ -3898,27 +3899,27 @@ def buildAttributes(self, node, attrs, already_processed):
38983899
if value is not None and 'id' not in already_processed:
38993900
already_processed.add('id')
39003901
self.id = value
3901-
value = find_attr_value_('primaryLanguage', node)
3902+
value = find_attr_value_('primaryLanguage', node) or self.parent_object_.primaryLanguage
39023903
if value is not None and 'primaryLanguage' not in already_processed:
39033904
already_processed.add('primaryLanguage')
39043905
self.primaryLanguage = value
39053906
self.validate_LanguageSimpleType(self.primaryLanguage) # validate type LanguageSimpleType
3906-
value = find_attr_value_('primaryScript', node)
3907+
value = find_attr_value_('primaryScript', node) or self.parent_object_.primaryScript
39073908
if value is not None and 'primaryScript' not in already_processed:
39083909
already_processed.add('primaryScript')
39093910
self.primaryScript = value
39103911
self.validate_ScriptSimpleType(self.primaryScript) # validate type ScriptSimpleType
3911-
value = find_attr_value_('secondaryScript', node)
3912+
value = find_attr_value_('secondaryScript', node) or self.parent_object_.secondaryScript
39123913
if value is not None and 'secondaryScript' not in already_processed:
39133914
already_processed.add('secondaryScript')
39143915
self.secondaryScript = value
39153916
self.validate_ScriptSimpleType(self.secondaryScript) # validate type ScriptSimpleType
3916-
value = find_attr_value_('readingDirection', node)
3917+
value = find_attr_value_('readingDirection', node) or self.parent_object_.readingDirection
39173918
if value is not None and 'readingDirection' not in already_processed:
39183919
already_processed.add('readingDirection')
39193920
self.readingDirection = value
39203921
self.validate_ReadingDirectionSimpleType(self.readingDirection) # validate type ReadingDirectionSimpleType
3921-
value = find_attr_value_('production', node)
3922+
value = find_attr_value_('production', node) or self.parent_object_.production
39223923
if value is not None and 'production' not in already_processed:
39233924
already_processed.add('production')
39243925
self.production = value
@@ -4399,27 +4400,27 @@ def buildAttributes(self, node, attrs, already_processed):
43994400
if value is not None and 'id' not in already_processed:
44004401
already_processed.add('id')
44014402
self.id = value
4402-
value = find_attr_value_('language', node)
4403+
value = find_attr_value_('language', node) or self.parent_object_.primaryLanguage
44034404
if value is not None and 'language' not in already_processed:
44044405
already_processed.add('language')
44054406
self.language = value
44064407
self.validate_LanguageSimpleType(self.language) # validate type LanguageSimpleType
4407-
value = find_attr_value_('primaryScript', node)
4408+
value = find_attr_value_('primaryScript', node) or self.parent_object_.primaryScript
44084409
if value is not None and 'primaryScript' not in already_processed:
44094410
already_processed.add('primaryScript')
44104411
self.primaryScript = value
44114412
self.validate_ScriptSimpleType(self.primaryScript) # validate type ScriptSimpleType
4412-
value = find_attr_value_('secondaryScript', node)
4413+
value = find_attr_value_('secondaryScript', node) or self.parent_object_.secondaryScript
44134414
if value is not None and 'secondaryScript' not in already_processed:
44144415
already_processed.add('secondaryScript')
44154416
self.secondaryScript = value
44164417
self.validate_ScriptSimpleType(self.secondaryScript) # validate type ScriptSimpleType
4417-
value = find_attr_value_('readingDirection', node)
4418+
value = find_attr_value_('readingDirection', node) or self.parent_object_.readingDirection
44184419
if value is not None and 'readingDirection' not in already_processed:
44194420
already_processed.add('readingDirection')
44204421
self.readingDirection = value
44214422
self.validate_ReadingDirectionSimpleType(self.readingDirection) # validate type ReadingDirectionSimpleType
4422-
value = find_attr_value_('production', node)
4423+
value = find_attr_value_('production', node) or self.parent_object_.production
44234424
if value is not None and 'production' not in already_processed:
44244425
already_processed.add('production')
44254426
self.production = value
@@ -4858,12 +4859,12 @@ def buildAttributes(self, node, attrs, already_processed):
48584859
self.symbol = False
48594860
else:
48604861
raise_parse_error(node, 'Bad boolean attribute')
4861-
value = find_attr_value_('script', node)
4862+
value = find_attr_value_('script', node) or self.parent_object_.primaryScript
48624863
if value is not None and 'script' not in already_processed:
48634864
already_processed.add('script')
48644865
self.script = value
48654866
self.validate_ScriptSimpleType(self.script) # validate type ScriptSimpleType
4866-
value = find_attr_value_('production', node)
4867+
value = find_attr_value_('production', node) or self.parent_object_.production
48674868
if value is not None and 'production' not in already_processed:
48684869
already_processed.add('production')
48694870
self.production = value
@@ -13918,6 +13919,22 @@ def build(self, node, gds_collector_=None):
1391813919
for child in node:
1391913920
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1392013921
self.buildChildren(child, node, nodeName_, gds_collector_=gds_collector_)
13922+
if not self.TextStyle and self.parent_object_.TextStyle:
13923+
self.TextStyle = copy.copy(self.parent_object_.TextStyle)
13924+
self.TextStyle.parent_object_ = self
13925+
if self.TextStyle:
13926+
for line in self.TextLine:
13927+
if not line.TextStyle:
13928+
line.TextStyle = copy.copy(self.TextStyle)
13929+
line.TextStyle.parent_object_ = line
13930+
for word in line.Word:
13931+
if not word.TextStyle:
13932+
word.TextStyle = copy.copy(self.TextStyle)
13933+
word.TextStyle.parent_object_ = word
13934+
for glyph in word.Glyph:
13935+
if not glyph.TextStyle:
13936+
glyph.TextStyle = copy.copy(self.TextStyle)
13937+
glyph.TextStyle.parent_object_ = glyph
1392113938
return self
1392213939
def buildAttributes(self, node, attrs, already_processed):
1392313940
value = find_attr_value_('orientation', node)
@@ -13934,12 +13951,12 @@ def buildAttributes(self, node, attrs, already_processed):
1393413951
if value is not None and 'leading' not in already_processed:
1393513952
already_processed.add('leading')
1393613953
self.leading = self.gds_parse_integer(value, node, 'leading')
13937-
value = find_attr_value_('readingDirection', node)
13954+
value = find_attr_value_('readingDirection', node) or self.parent_object_.readingDirection
1393813955
if value is not None and 'readingDirection' not in already_processed:
1393913956
already_processed.add('readingDirection')
1394013957
self.readingDirection = value
1394113958
self.validate_ReadingDirectionSimpleType(self.readingDirection) # validate type ReadingDirectionSimpleType
13942-
value = find_attr_value_('textLineOrder', node)
13959+
value = find_attr_value_('textLineOrder', node) or self.parent_object_.textLineOrder
1394313960
if value is not None and 'textLineOrder' not in already_processed:
1394413961
already_processed.add('textLineOrder')
1394513962
self.textLineOrder = value
@@ -13963,22 +13980,22 @@ def buildAttributes(self, node, attrs, already_processed):
1396313980
already_processed.add('align')
1396413981
self.align = value
1396513982
self.validate_AlignSimpleType(self.align) # validate type AlignSimpleType
13966-
value = find_attr_value_('primaryLanguage', node)
13983+
value = find_attr_value_('primaryLanguage', node) or self.parent_object_.primaryLanguage
1396713984
if value is not None and 'primaryLanguage' not in already_processed:
1396813985
already_processed.add('primaryLanguage')
1396913986
self.primaryLanguage = value
1397013987
self.validate_LanguageSimpleType(self.primaryLanguage) # validate type LanguageSimpleType
13971-
value = find_attr_value_('secondaryLanguage', node)
13988+
value = find_attr_value_('secondaryLanguage', node) or self.parent_object_.secondaryLanguage
1397213989
if value is not None and 'secondaryLanguage' not in already_processed:
1397313990
already_processed.add('secondaryLanguage')
1397413991
self.secondaryLanguage = value
1397513992
self.validate_LanguageSimpleType(self.secondaryLanguage) # validate type LanguageSimpleType
13976-
value = find_attr_value_('primaryScript', node)
13993+
value = find_attr_value_('primaryScript', node) or self.parent_object_.primaryScript
1397713994
if value is not None and 'primaryScript' not in already_processed:
1397813995
already_processed.add('primaryScript')
1397913996
self.primaryScript = value
1398013997
self.validate_ScriptSimpleType(self.primaryScript) # validate type ScriptSimpleType
13981-
value = find_attr_value_('secondaryScript', node)
13998+
value = find_attr_value_('secondaryScript', node) or self.parent_object_.secondaryScript
1398213999
if value is not None and 'secondaryScript' not in already_processed:
1398314000
already_processed.add('secondaryScript')
1398414001
self.secondaryScript = value
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
diff --git a/ocrd_models/ocrd_models/ocrd_page_generateds.py b/ocrd_models/ocrd_models/ocrd_page_generateds.py
2+
index 98111b0c..2ad8e9e4 100644
3+
--- a/ocrd_models/ocrd_models/ocrd_page_generateds.py
4+
+++ b/ocrd_models/ocrd_models/ocrd_page_generateds.py
5+
@@ -27,6 +27,7 @@
6+
from six.moves import zip_longest
7+
import os
8+
import sys
9+
+import copy
10+
import re as re_
11+
import base64
12+
import datetime as datetime_
13+
@@ -3944,27 +3945,27 @@ class TextLineType(GeneratedsSuper):
14+
if value is not None and 'id' not in already_processed:
15+
already_processed.add('id')
16+
self.id = value
17+
- value = find_attr_value_('primaryLanguage', node)
18+
+ value = find_attr_value_('primaryLanguage', node) or self.parent_object_.primaryLanguage
19+
if value is not None and 'primaryLanguage' not in already_processed:
20+
already_processed.add('primaryLanguage')
21+
self.primaryLanguage = value
22+
self.validate_LanguageSimpleType(self.primaryLanguage) # validate type LanguageSimpleType
23+
- value = find_attr_value_('primaryScript', node)
24+
+ value = find_attr_value_('primaryScript', node) or self.parent_object_.primaryScript
25+
if value is not None and 'primaryScript' not in already_processed:
26+
already_processed.add('primaryScript')
27+
self.primaryScript = value
28+
self.validate_ScriptSimpleType(self.primaryScript) # validate type ScriptSimpleType
29+
- value = find_attr_value_('secondaryScript', node)
30+
+ value = find_attr_value_('secondaryScript', node) or self.parent_object_.secondaryScript
31+
if value is not None and 'secondaryScript' not in already_processed:
32+
already_processed.add('secondaryScript')
33+
self.secondaryScript = value
34+
self.validate_ScriptSimpleType(self.secondaryScript) # validate type ScriptSimpleType
35+
- value = find_attr_value_('readingDirection', node)
36+
+ value = find_attr_value_('readingDirection', node) or self.parent_object_.readingDirection
37+
if value is not None and 'readingDirection' not in already_processed:
38+
already_processed.add('readingDirection')
39+
self.readingDirection = value
40+
self.validate_ReadingDirectionSimpleType(self.readingDirection) # validate type ReadingDirectionSimpleType
41+
- value = find_attr_value_('production', node)
42+
+ value = find_attr_value_('production', node) or self.parent_object_.production
43+
if value is not None and 'production' not in already_processed:
44+
already_processed.add('production')
45+
self.production = value
46+
@@ -4453,27 +4454,27 @@ class WordType(GeneratedsSuper):
47+
if value is not None and 'id' not in already_processed:
48+
already_processed.add('id')
49+
self.id = value
50+
- value = find_attr_value_('language', node)
51+
+ value = find_attr_value_('language', node) or self.parent_object_.primaryLanguage
52+
if value is not None and 'language' not in already_processed:
53+
already_processed.add('language')
54+
self.language = value
55+
self.validate_LanguageSimpleType(self.language) # validate type LanguageSimpleType
56+
- value = find_attr_value_('primaryScript', node)
57+
+ value = find_attr_value_('primaryScript', node) or self.parent_object_.primaryScript
58+
if value is not None and 'primaryScript' not in already_processed:
59+
already_processed.add('primaryScript')
60+
self.primaryScript = value
61+
self.validate_ScriptSimpleType(self.primaryScript) # validate type ScriptSimpleType
62+
- value = find_attr_value_('secondaryScript', node)
63+
+ value = find_attr_value_('secondaryScript', node) or self.parent_object_.secondaryScript
64+
if value is not None and 'secondaryScript' not in already_processed:
65+
already_processed.add('secondaryScript')
66+
self.secondaryScript = value
67+
self.validate_ScriptSimpleType(self.secondaryScript) # validate type ScriptSimpleType
68+
- value = find_attr_value_('readingDirection', node)
69+
+ value = find_attr_value_('readingDirection', node) or self.parent_object_.readingDirection
70+
if value is not None and 'readingDirection' not in already_processed:
71+
already_processed.add('readingDirection')
72+
self.readingDirection = value
73+
self.validate_ReadingDirectionSimpleType(self.readingDirection) # validate type ReadingDirectionSimpleType
74+
- value = find_attr_value_('production', node)
75+
+ value = find_attr_value_('production', node) or self.parent_object_.production
76+
if value is not None and 'production' not in already_processed:
77+
already_processed.add('production')
78+
self.production = value
79+
@@ -4920,12 +4921,12 @@ class GlyphType(GeneratedsSuper):
80+
self.symbol = False
81+
else:
82+
raise_parse_error(node, 'Bad boolean attribute')
83+
- value = find_attr_value_('script', node)
84+
+ value = find_attr_value_('script', node) or self.parent_object_.primaryScript
85+
if value is not None and 'script' not in already_processed:
86+
already_processed.add('script')
87+
self.script = value
88+
self.validate_ScriptSimpleType(self.script) # validate type ScriptSimpleType
89+
- value = find_attr_value_('production', node)
90+
+ value = find_attr_value_('production', node) or self.parent_object_.production
91+
if value is not None and 'production' not in already_processed:
92+
already_processed.add('production')
93+
self.production = value
94+
@@ -14332,6 +14333,22 @@ class TextRegionType(RegionType):
95+
for child in node:
96+
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
97+
self.buildChildren(child, node, nodeName_, gds_collector_=gds_collector_)
98+
+ if not self.TextStyle and self.parent_object_.TextStyle:
99+
+ self.TextStyle = copy.copy(self.parent_object_.TextStyle)
100+
+ self.TextStyle.parent_object_ = self
101+
+ if self.TextStyle:
102+
+ for line in self.TextLine:
103+
+ if not line.TextStyle:
104+
+ line.TextStyle = copy.copy(self.TextStyle)
105+
+ line.TextStyle.parent_object_ = line
106+
+ for word in line.Word:
107+
+ if not word.TextStyle:
108+
+ word.TextStyle = copy.copy(self.TextStyle)
109+
+ word.TextStyle.parent_object_ = word
110+
+ for glyph in word.Glyph:
111+
+ if not glyph.TextStyle:
112+
+ glyph.TextStyle = copy.copy(self.TextStyle)
113+
+ glyph.TextStyle.parent_object_ = glyph
114+
return self
115+
def buildAttributes(self, node, attrs, already_processed):
116+
value = find_attr_value_('orientation', node)
117+
@@ -14348,12 +14365,12 @@ class TextRegionType(RegionType):
118+
if value is not None and 'leading' not in already_processed:
119+
already_processed.add('leading')
120+
self.leading = self.gds_parse_integer(value, node, 'leading')
121+
- value = find_attr_value_('readingDirection', node)
122+
+ value = find_attr_value_('readingDirection', node) or self.parent_object_.readingDirection
123+
if value is not None and 'readingDirection' not in already_processed:
124+
already_processed.add('readingDirection')
125+
self.readingDirection = value
126+
self.validate_ReadingDirectionSimpleType(self.readingDirection) # validate type ReadingDirectionSimpleType
127+
- value = find_attr_value_('textLineOrder', node)
128+
+ value = find_attr_value_('textLineOrder', node) or self.parent_object_.textLineOrder
129+
if value is not None and 'textLineOrder' not in already_processed:
130+
already_processed.add('textLineOrder')
131+
self.textLineOrder = value
132+
@@ -14377,22 +14394,22 @@ class TextRegionType(RegionType):
133+
already_processed.add('align')
134+
self.align = value
135+
self.validate_AlignSimpleType(self.align) # validate type AlignSimpleType
136+
- value = find_attr_value_('primaryLanguage', node)
137+
+ value = find_attr_value_('primaryLanguage', node) or self.parent_object_.primaryLanguage
138+
if value is not None and 'primaryLanguage' not in already_processed:
139+
already_processed.add('primaryLanguage')
140+
self.primaryLanguage = value
141+
self.validate_LanguageSimpleType(self.primaryLanguage) # validate type LanguageSimpleType
142+
- value = find_attr_value_('secondaryLanguage', node)
143+
+ value = find_attr_value_('secondaryLanguage', node) or self.parent_object_.secondaryLanguage
144+
if value is not None and 'secondaryLanguage' not in already_processed:
145+
already_processed.add('secondaryLanguage')
146+
self.secondaryLanguage = value
147+
self.validate_LanguageSimpleType(self.secondaryLanguage) # validate type LanguageSimpleType
148+
- value = find_attr_value_('primaryScript', node)
149+
+ value = find_attr_value_('primaryScript', node) or self.parent_object_.primaryScript
150+
if value is not None and 'primaryScript' not in already_processed:
151+
already_processed.add('primaryScript')
152+
self.primaryScript = value
153+
self.validate_ScriptSimpleType(self.primaryScript) # validate type ScriptSimpleType
154+
- value = find_attr_value_('secondaryScript', node)
155+
+ value = find_attr_value_('secondaryScript', node) or self.parent_object_.secondaryScript
156+
if value is not None and 'secondaryScript' not in already_processed:
157+
already_processed.add('secondaryScript')
158+
self.secondaryScript = value

0 commit comments

Comments
 (0)