|
|
@ -4,16 +4,41 @@ import os |
|
|
canto_dir = os.path.abspath(os.getcwd()) |
|
|
canto_dir = os.path.abspath(os.getcwd()) |
|
|
print('\n\n====================' + canto_dir + '====================') |
|
|
print('\n\n====================' + canto_dir + '====================') |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
Define XML file name |
|
|
|
|
|
Load txt file |
|
|
|
|
|
Iterate through lines in txt file |
|
|
|
|
|
Iterate through words in each line |
|
|
|
|
|
Iterate through each letter from end to beginning |
|
|
|
|
|
catch single chars like `-` |
|
|
|
|
|
catch single chars at end of line like `-\n` |
|
|
|
|
|
if the char is not `’` or `-` or alphabetical, go to the next letter in word (backwards) |
|
|
|
|
|
else separate the ending punct from beginning chars |
|
|
|
|
|
Iterate through each letter from beginning to remainder of word |
|
|
|
|
|
if no punctuation, then all remainder is middle chars |
|
|
|
|
|
catch single chars like `-\n` |
|
|
|
|
|
if the char is not `‘` or `’` or `-` or alphabetical, go to the next letter in word (forwards) |
|
|
|
|
|
else separate middle chars from beginning punctuation |
|
|
|
|
|
Build the tag word from <beginning punct> + <middle chars> + <ending punct> |
|
|
|
|
|
Write the tag word to the temp XML file |
|
|
|
|
|
Open the temp XML file |
|
|
|
|
|
Iterate over lines |
|
|
|
|
|
Catch double spaces |
|
|
|
|
|
Catch leading spaces |
|
|
|
|
|
Add leading tabs and leading line tag |
|
|
|
|
|
Add closing line tag |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
def add_tags(canto_txt_file): |
|
|
def add_tags(canto_txt_file): |
|
|
# Only grab 0XX-canticle from `*.txt` file names |
|
|
# only grab 0xx-canticle from `*.txt` file names |
|
|
xmlfile = canto_txt_file.split('.')[0] + '.xml' |
|
|
xmlfile = canto_txt_file.split('.')[0] + '.xml' |
|
|
tmpxmlfile = '.' + canto_txt_file.split('.')[0] + '.tmp.xml' |
|
|
tmpxmlfile = '.' + canto_txt_file.split('.')[0] + '.tmp.xml' |
|
|
with open(xmlfile,'w') as Cxml: |
|
|
with open(xmlfile,'w') as cxml: |
|
|
with open(tmpxmlfile,'w') as Cxmltmp: |
|
|
with open(tmpxmlfile,'w') as cxmltmp: |
|
|
with open(canto_txt_file,'r') as Ctxt: |
|
|
with open(canto_txt_file,'r') as ctxt: |
|
|
for spaced_line in Ctxt: |
|
|
for spaced_line in ctxt: |
|
|
# Use `~` as a placeholder for spaces later |
|
|
# use `~` as a placeholder for spaces later |
|
|
line = re.sub(' ','~',spaced_line) |
|
|
line = re.sub(' ','~',spaced_line) |
|
|
words = line.split('~') |
|
|
words = line.split('~') |
|
|
for i in range(len(words)): |
|
|
for i in range(len(words)): |
|
|
|