comparison lxmldump.py @ 17:6fa24c711f86

Add some comments.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 May 2021 15:12:14 +0300
parents 285b0820d2c6
children ff959de0f6c8
comparison
equal deleted inserted replaced
16:285b0820d2c6 17:6fa24c711f86
139 pkk_printi(indent, "{}{}{}\n".format(lnode.tag, atmp, stmp)) 139 pkk_printi(indent, "{}{}{}\n".format(lnode.tag, atmp, stmp))
140 for qnode in lnode.findall("./*"): 140 for qnode in lnode.findall("./*"):
141 pkk_dump_recursive(indent + 1, qnode) 141 pkk_dump_recursive(indent + 1, qnode)
142 142
143 143
144 ## Output item under given node 144 ## Output item(s) under given node with given format string
145 def pkk_output_subs_fmt(indent, dnode, dsub, dname, dfmt): 145 def pkk_output_subs_fmt(indent, dnode, dsub, dname, dfmt):
146 for qnode in dnode.findall(dsub): 146 for qnode in dnode.findall(dsub):
147 pkk_printi(indent, dfmt.format(dname, pkk_node_to_text(qnode))) 147 pkk_printi(indent, dfmt.format(dname, pkk_node_to_text(qnode)))
148 148
149 149 ## Output item(s) under given node with a prefixed name string
150 def pkk_output_subs_prefix(indent, dnode, dsub, dname): 150 def pkk_output_subs_prefix(indent, dnode, dsub, dname):
151 pkk_output_subs_fmt(indent, dnode, dsub, dname, "{0} \"{1}\"\n") 151 pkk_output_subs_fmt(indent, dnode, dsub, dname, "{0} \"{1}\"\n")
152 152
153 153
154 ## Output a main "Headword" or "Sense" node under it
154 def pkk_output_sense(indent, dnode): 155 def pkk_output_sense(indent, dnode):
156 # Search form and definition
155 pkk_output_subs_prefix(indent, dnode, "./SearchForm", "srch") 157 pkk_output_subs_prefix(indent, dnode, "./SearchForm", "srch")
156 pkk_output_subs_prefix(indent, dnode, "./Definition", "defn") 158 pkk_output_subs_prefix(indent, dnode, "./Definition", "defn")
157 159
160 # Examples
158 for wnode in dnode.findall("./ExampleBlock/ExampleCtn"): 161 for wnode in dnode.findall("./ExampleBlock/ExampleCtn"):
159 sstr = pkk_node_to_text(wnode.find("./Example")) 162 sstr = pkk_node_to_text(wnode.find("./Example"))
160 lstr = "" 163 lstr = ""
161 164
162 if pkk_verbosity(1): 165 if pkk_verbosity(1):
168 lstr = " ({})".format(", ".join(ltmp)) 171 lstr = " ({})".format(", ".join(ltmp))
169 172
170 pkk_printi(indent + 1, "{} \"{}\"{}\n".format("exmp", sstr, lstr)) 173 pkk_printi(indent + 1, "{} \"{}\"{}\n".format("exmp", sstr, lstr))
171 174
172 175
176 ## Output one "DictionaryEntry" node
173 def pkk_output_node(indent, dnode): 177 def pkk_output_node(indent, dnode):
174 178
175 for wnode in dnode.findall("./HeadwordCtn"): 179 for wnode in dnode.findall("./HeadwordCtn"):
176 pkk_output_subs_fmt(indent, wnode, "./Headword", "", "\"{1}\":\n") 180 pkk_output_subs_fmt(indent, wnode, "./Headword", "", "\"{1}\":\n")
177 pkk_output_sense(indent + 1, wnode) 181 pkk_output_sense(indent + 1, wnode)