Browse Source

add line num attrs

main
lhess2021 4 years ago
parent
commit
817872e0c1
  1. 6
      py-scripts.d/word-tags.py

6
py-scripts.d/word-tags.py

@ -4,6 +4,7 @@ import os
canto_dir = os.path.abspath(os.getcwd())
print('\n\n====================' + canto_dir + '====================')
def add_tags(canto_txt_file):
# Only grab 0XX-canticle from `*.txt` file names
xmlfile = canto_txt_file.split('.')[0] + '.xml'
@ -64,16 +65,19 @@ def add_tags(canto_txt_file):
def add_space(match):
match = match.group()
return re.sub('<w>', ' <w>', match)
j = 1
for line in Cxmltmp:
# Swap double spaces from new_word with single spaces
line_spaced = re.sub(' ',' ',line)
# If there's a single space at the beginning of the line, delete it
line_spaced = line_spaced.lstrip(' ')
# Add three tabs and opening line tags at the beginning
line_spaced = re.sub('^','\t\t\t\t\t<l> ',line_spaced)
line_tag = '\t\t\t\t\t<l l_num="' + str(j) + '"> '
line_spaced = re.sub('^',line_tag,line_spaced)
# Add closing line tags
line_spaced = re.sub('\n',' </l>\n',line_spaced)
Cxml.write(line_spaced)
j += 1
Cxmltmp.close()
os.remove(tmpxmlfile)
Cxml.close()

Loading…
Cancel
Save