# %%
# Imports
import xml.etree.ElementTree as ET
import json
import os
basedir = '/Users/federicaspinelli/TEAMOVI/Parser/DATA/'
baseindir = basedir + 'OVI/datiniXML/xmlgat/'
baseoutdir = basedir + 'OVI/datiniXML/xmlevt/'
# %%
# This is to handle the xmnls attribute in the TEI element in the templates
uri1 = "{http://www.tei-c.org/ns/1.0}"
namespaces = {
'': "http://www.tei-c.org/ns/1.0",
}
for prefix, uri in namespaces.items():
ET.register_namespace(prefix, uri)
# Reference directories
basedir = '/Users/federicaspinelli/TEAMOVI/Parser/DATA/'
baseindir = basedir + 'OVI/datiniXML/xmlgat/'
baseoutdir = basedir + 'OVI/datiniXML/xmlevt/'
# %%
# Import lems list + xml info file
# get lem list as a json object
lemfile = '/Users/federicaspinelli/TEAMOVI/Parser/OVI/Lemmi/associazione lemmi - link TLIO/power_lemmarioD_link.json'
lems = json.load(open(lemfile, 'r'))
# %%
persNames = [lem for lem in lems if lem['lemma']['categoria']=='antr.']
placeNames = [lem for lem in lems if lem['lemma']['categoria']=='n.g.']
lemNames = [lem for lem in lems if lem['lemma']['categoria']!='antr.' or lem['lemma']['categoria']!='n.g.']
fileNames = os.listdir(baseoutdir + "lettere/")
# %%
print(len(persNames), len(lems), len(placeNames), len(lemNames))
print(len(os.listdir(baseindir)), len(os.listdir(baseoutdir + 'lettere/')))
# %%
placeTemplate ='''
PLACE_NAME
PLACE_NOTE
'''
personTemplate ='''
PERSON_NAME
PERSON_NOTE
'''
lemTemplate ='''
-
LEM_NAME
"LEM_REF"
LEM_NOTE
'''
uriTemplate = ''' '''
fileTemplate = ''
fileIndent = ' '
# %%
persNames[10]
# %%
persListString = ""
for person in persNames:
persListString = persListString + personTemplate.replace('PERSON_ID', ''+str(person['id'])).replace('PERSON_NAME', person['lemma']['forma_standard']).replace('PERSON_NOTE', person['lemma']['note'])
placeListString = ""
for place in placeNames:
placeListString = placeListString + placeTemplate.replace('PLACE_ID', ''+str(place['id'])).replace('PLACE_NAME', place['lemma']['forma_standard']).replace('PLACE_NOTE', place['lemma']['note'])
lemListString = ""
for lemma in lemNames:
lemListString = lemListString + lemTemplate.replace('LEM_ID', ''+str(lemma['id'])).replace('LEM_NAME', lemma['lemma']['forma_standard']).replace('LEM_CAT', lemma['lemma']['categoria']).replace('LEM_NOTE', lemma['lemma']['note']).replace('LEM_IPER', lemma['lemma']['iperlemma']).replace('LEM_REF', str(lemma['lemma']['uri'])).replace('\"[\'', ' ")
fileListString = ""
for ii, f1 in enumerate(fileNames):
fileListString = fileListString + fileTemplate.replace('LETTER_FILENAME', f1).replace('LETTER_TEXTPOINT', f1.replace('.xml', '_text'))
if ii', persListString).replace('', placeListString).replace('', lemListString).replace('', fileListString)
# %%
with open('test_main.xml', 'w') as f2:
f2.write(mainFileString)
# %%
with open(baseoutdir + 'main.xml', 'w') as f3:
f3.write(mainFileString)
# %%
# %%