Skip to content

Commit

Permalink
Correct with for python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
kleag committed May 23, 2024
1 parent 596f21e commit 74bc5ea
Showing 1 changed file with 56 additions and 58 deletions.
114 changes: 56 additions & 58 deletions lima_linguisticdata/scripts/xmlforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,64 +58,62 @@ def main():

args = parser.parse_args()

with (
codecs.open(args.inputfile, "r", "utf-8") as source,
codecs.open(args.outputfile, "a", "utf-8") as out
):
form = ""
lemma = ""
norm = ""

count = 0
icount = 0

lines = source.readlines()
for line in tqdm(lines, desc="Processing lines", unit="line"):
line = line.strip()
line = (
line.replace("&", "&")
.replace('"', """)
.replace("<", "&lt;")
.replace(">", "&gt;")
)
if line == "":
continue

line = line.split("#")[0].strip()
data = line.split("\t")
if line == "" or len(data) != 4:
print(f"xmlform: Invalid line '{line}'")
continue

if data[0] != form:
form = data[0]
if count > 0:
out.write(" </i>\n</entry>\n")
out.write(f'<entry k="{form}"')
if args.desacc:
out.write(f' desacc="{args.desacc}"')
if args.entryop:
out.write(f' op="{args.entryop}"')
out.write(">\n")
icount = 0
count += 1

if icount == 0 or data[1] != lemma or data[2] != norm:
lemma = data[1]
norm = data[2]
if icount > 0:
out.write(" </i>\n")
out.write(" <i")
if lemma:
out.write(f' l="{lemma}"')
if norm:
out.write(f' n="{norm}"')
if args.lingop:
out.write(f' op="{args.lingop}"')
out.write(">\n")
icount += 1

out.write(f' <p v="{data[3]}"/>\n')
with codecs.open(args.inputfile, "r", "utf-8") as source:
with codecs.open(args.outputfile, "a", "utf-8") as out:
form = ""
lemma = ""
norm = ""

count = 0
icount = 0

lines = source.readlines()
for line in tqdm(lines, desc="Processing lines", unit="line"):
line = line.strip()
line = (
line.replace("&", "&amp;")
.replace('"', "&quot;")
.replace("<", "&lt;")
.replace(">", "&gt;")
)
if line == "":
continue

line = line.split("#")[0].strip()
data = line.split("\t")
if line == "" or len(data) != 4:
print(f"xmlform: Invalid line '{line}'")
continue

if data[0] != form:
form = data[0]
if count > 0:
out.write(" </i>\n</entry>\n")
out.write(f'<entry k="{form}"')
if args.desacc:
out.write(f' desacc="{args.desacc}"')
if args.entryop:
out.write(f' op="{args.entryop}"')
out.write(">\n")
icount = 0
count += 1

if icount == 0 or data[1] != lemma or data[2] != norm:
lemma = data[1]
norm = data[2]
if icount > 0:
out.write(" </i>\n")
out.write(" <i")
if lemma:
out.write(f' l="{lemma}"')
if norm:
out.write(f' n="{norm}"')
if args.lingop:
out.write(f' op="{args.lingop}"')
out.write(">\n")
icount += 1

out.write(f' <p v="{data[3]}"/>\n')

if count > 0:
out.write(" </i>\n</entry>\n")
Expand Down

0 comments on commit 74bc5ea

Please sign in to comment.