diff --git a/py-scripts.d/word-tags.py b/py-scripts.d/word-tags.py index b1ee6d1..93e31fb 100644 --- a/py-scripts.d/word-tags.py +++ b/py-scripts.d/word-tags.py @@ -4,16 +4,41 @@ import os canto_dir = os.path.abspath(os.getcwd()) 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 + + +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): - # Only grab 0XX-canticle from `*.txt` file names + # only grab 0xx-canticle from `*.txt` file names xmlfile = canto_txt_file.split('.')[0] + '.xml' tmpxmlfile = '.' + canto_txt_file.split('.')[0] + '.tmp.xml' - with open(xmlfile,'w') as Cxml: - with open(tmpxmlfile,'w') as Cxmltmp: - with open(canto_txt_file,'r') as Ctxt: - for spaced_line in Ctxt: - # Use `~` as a placeholder for spaces later + with open(xmlfile,'w') as cxml: + with open(tmpxmlfile,'w') as cxmltmp: + with open(canto_txt_file,'r') as ctxt: + for spaced_line in ctxt: + # use `~` as a placeholder for spaces later line = re.sub(' ','~',spaced_line) words = line.split('~') for i in range(len(words)):