|
|
|
@ -1,21 +1,16 @@ |
|
|
|
import re |
|
|
|
import os |
|
|
|
|
|
|
|
""" |
|
|
|
Replace every space with a special character and then re-replace them? You lose the space between `:«` with current method. |
|
|
|
""" |
|
|
|
canto_dir = os.path.abspath(os.getcwd()) |
|
|
|
print('\n\n====================' + canto_dir + '====================') |
|
|
|
|
|
|
|
path = __file__ |
|
|
|
|
|
|
|
directory = os.path.abspath(os.getcwd()) |
|
|
|
|
|
|
|
def add_tags(filename): |
|
|
|
def add_tags(canto_txt_file): |
|
|
|
# Only grab 0XX-canticle from `*.txt` file names |
|
|
|
xmlfile = filename.split('.')[0] + '.xml' |
|
|
|
tmpxmlfile = '.' + filename.split('.')[0] + '.tmp.xml' |
|
|
|
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(filename,'r') as Ctxt: |
|
|
|
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) |
|
|
|
@ -33,7 +28,7 @@ def add_tags(filename): |
|
|
|
before_end_word_chars = word.rstrip() |
|
|
|
ending_punct_chars = '\n' |
|
|
|
else: |
|
|
|
print('Got to <- with: ' + word + ' and this L: ' + str(L) + ' in ' + filename) |
|
|
|
print('Got to <- with: ' + word + ' and this L: ' + str(L) + ' in ' + canto_txt_file) |
|
|
|
# We need `word[L] != '-'` because there are some words like `-:` |
|
|
|
while word[L] != '’' and word[L] != '-' and not word[L].isalpha(): |
|
|
|
L-=1 |
|
|
|
@ -50,7 +45,7 @@ def add_tags(filename): |
|
|
|
middle_word_chars = word.rstrip() |
|
|
|
starting_punct_chars = '' |
|
|
|
else: |
|
|
|
#print('Got -> with this word: ' + word + ' and this L: ' + str(L) + ' in ' + filename) |
|
|
|
print('Got -> with this word: ' + word + ' and this L: ' + str(L) + ' in ' + canto_txt_file) |
|
|
|
while word[-L - 1] != '‘' and word[-L - 1] != '’' and word[L] != '-' and not word[-L - 1].isalpha(): |
|
|
|
L-=1 |
|
|
|
else: |
|
|
|
@ -81,8 +76,8 @@ def add_tags(filename): |
|
|
|
os.remove(tmpxmlfile) |
|
|
|
Cxml.close() |
|
|
|
|
|
|
|
for f in os.listdir(directory): |
|
|
|
if f != 'word-tags.py' and f != '.word-tags.py.swp': |
|
|
|
add_tags(f) |
|
|
|
if f.endswith('.txt'): |
|
|
|
os.remove(os.path.join(directory, f)) |
|
|
|
for canto in os.listdir(canto_dir): |
|
|
|
if canto != 'word-tags.py' and canto != '.word-tags.py.swp': |
|
|
|
add_tags(canto) |
|
|
|
if canto.endswith('.txt'): |
|
|
|
os.remove(os.path.join(canto_dir, canto)) |
|
|
|
|