|
|
|
@ -1,12 +1,14 @@ |
|
|
|
import re |
|
|
|
import os |
|
|
|
import xml.etree.ElementTree as ET |
|
|
|
import glob |
|
|
|
import shutil |
|
|
|
|
|
|
|
""" |
|
|
|
This script takes xml canto files and counts the number of unique words as |
|
|
|
defined by the value of `<w>` nodes. |
|
|
|
|
|
|
|
8 files are generated: csv and html of |
|
|
|
8 files are generated: csv and html of cantos |
|
|
|
- sorted numerically and alphabetically |
|
|
|
- sorted numerically and alphabetically with blacklist applied |
|
|
|
""" |
|
|
|
@ -28,6 +30,7 @@ def createWordCountDict(cantoFile): |
|
|
|
wordCountDict[xpathValue(node)] = 1 |
|
|
|
""" |
|
|
|
wordCountDict = dict() |
|
|
|
print(cantoFile) |
|
|
|
tree = ET.parse(cantoFile) |
|
|
|
root = tree.getroot() |
|
|
|
# TODO |
|
|
|
@ -97,6 +100,41 @@ def dictToHtml(sortedDict, sortType, cantoFile): |
|
|
|
htmlCanto.write(boilerclose) |
|
|
|
htmlCanto.close() |
|
|
|
|
|
|
|
def makeDirs(): |
|
|
|
# moves *.csv to ../comedy-wordcount.d/csv/... |
|
|
|
# moves *.html to ../comedy-wordcount.d/html/... |
|
|
|
csvFiles = glob.iglob(os.path.join(cantoDir, '*.csv')) |
|
|
|
htmlFiles = glob.iglob(os.path.join(cantoDir, '*.html')) |
|
|
|
for csvFile in csvFiles: |
|
|
|
canticle = csvFile.split('/')[-1].split('-')[1] |
|
|
|
if re.search('num\.', csvFile): |
|
|
|
numDir = '../../comedy-wordcount.d/csv/' + canticle + '-num/' |
|
|
|
shutil.move(csvFile, numDir) |
|
|
|
if re.search('num-black', csvFile): |
|
|
|
numBlackDir = '../../comedy-wordcount.d/csv/' + canticle + '-num-black/' |
|
|
|
shutil.move(csvFile, numBlackDir) |
|
|
|
if re.search('alpha\.', csvFile): |
|
|
|
alphaDir = '../../comedy-wordcount.d/csv/' + canticle + '-alpha/' |
|
|
|
shutil.move(csvFile, alphaDir) |
|
|
|
if re.search('alpha-black', csvFile): |
|
|
|
alphaBlackDir = '../../comedy-wordcount.d/csv/' + canticle + '-alpha-black/' |
|
|
|
shutil.move(csvFile, alphaBlackDir) |
|
|
|
for htmlFile in htmlFiles: |
|
|
|
canticle = htmlFile.split('/')[-1].split('-')[1] |
|
|
|
if re.search('num\.', htmlFile): |
|
|
|
numDir = '../../comedy-wordcount.d/html/' + canticle + '-num/' |
|
|
|
shutil.move(htmlFile, numDir) |
|
|
|
if re.search('num-black', htmlFile): |
|
|
|
numBlackDir = '../../comedy-wordcount.d/html/' + canticle + '-num-black/' |
|
|
|
shutil.move(htmlFile, numBlackDir) |
|
|
|
if re.search('alpha\.', htmlFile): |
|
|
|
alphaDir = '../../comedy-wordcount.d/html/' + canticle + '-alpha/' |
|
|
|
shutil.move(htmlFile, alphaDir) |
|
|
|
if re.search('alpha-black', htmlFile): |
|
|
|
alphaBlackDir = '../../comedy-wordcount.d/html/' + canticle + '-alpha-black/' |
|
|
|
shutil.move(htmlFile, alphaBlackDir) |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
for canto in os.listdir(cantoDir): |
|
|
|
if re.search('\.xml$', canto): |
|
|
|
@ -120,5 +158,7 @@ def main(): |
|
|
|
dictToHtml(wordCountDictAlphaSorted, 'alpha', cantoFile) |
|
|
|
dictToHtml(wordCountDictAlphaSortedBlack, 'alpha-black', cantoFile) |
|
|
|
|
|
|
|
makeDirs() |
|
|
|
|
|
|
|
|
|
|
|
main() |
|
|
|
|