Permalink
Browse files

Add FilteredCorpus reader, helper methods, organize latin corpus type…

…s, correct prosody annotations, etc (#846)

* Initial releases with unit tests and doctests

* Added sections and preliminary documentation for:
Scansion of Poetry
About the use of macrons in poetry
HexameterScanner
Hexameter
ScansionConstants
Syllabifier
Metrical Validator
ScansionFormatter
StringUtils module

Made minor formatting corrections elsewhere to quiet warnings encountered during transpiling the rst file during testing and verification.

* corrected documentation & doctest comments that were causing errors.
doctests run with an added command line switch:
nosetests --no-skip --with-coverage --cover-package=cltk --with-doctest

* fixing broken doctest comment

* correcting documentation comment that causes doctest to err

* Corrections to make the build pass:
1. added install gensim to travis build script; its absence is causing an error in word2vec.py during the build.
2. Modified transcription.py so that the macronizer is initialized on instantiation of the Transcriber class and not at the module level; the macronizer file is 32MB and this also seems to cause an error with travis as github does not make large files displayable, and so it may not be available for the build. The macronizer object has been made a component of "self."

* moved package import inside of main so that it does not prevent the build from completing;
soon, we should move to update the dependencies of word2vec; gensim pulls in boto which isn't python3 compliant, there is a boto3 version which we may be able to slot in, but perhaps a larger question is boto necessary?

* correcting documentation

* corrections for type annotations

* corrections for type annotations, renaming modules to be more in alignment with standard Python naming conventions

* Adding FilteredCorpusReader, and assemble_corpus function, with tests.
Adding utility code for featurization, functions for matrix operations on a corpus in matrix format.
Adding latin library corpus type file and directory mapping.
Doctest incorporated for every function.

* adding get_corpus_reader to latin corpus

* corrections for type annotations

* corrections for tests

* corrections for tests

* increasing test coverage

* adjusting travis to pull the test corpora

* remove unused imports

* making FilteredCorpus tests more clear about what they are looking for

* add corpus_readers documentation, clean up readers and test_corpus

* add carriage return
  • Loading branch information...
todd-cook authored and kylepjohnson committed Jan 6, 2019
1 parent de1fd6d commit 320e810184204d9171e683241adea4c5c1c73a04
@@ -24,6 +24,7 @@ before_script:
- pip install numpy
- pip install scipy
- pip install scikit-learn
- python cltk/tests/download_test_corpora.py

script:
# Notes on nose:
@@ -1,44 +1,11 @@
# CLTK: Latin Corpus Readers

__author__ = ['Patrick J. Burns <patrick@diyclassics.org>']
__license__ = 'MIT License. See LICENSE.'

"""
CLTK Latin corpus readers
CLTK: Corpus Latin properties
"""

import os.path
from nltk.corpus.reader.plaintext import PlaintextCorpusReader
from nltk.tokenize.punkt import PunktSentenceTokenizer, PunktParameters

from cltk.tokenize.sentence import TokenizeSentence
from cltk.tokenize.word import WordTokenizer

# Would like to have this search through a CLTK_DATA environment variable
# Better to use something like make_cltk_path in cltk.utils.file_operations?
home = os.path.expanduser('~')
cltk_path = os.path.join(home, 'cltk_data')
if not os.path.isdir(cltk_path):
os.makedirs(cltk_path)

word_tokenizer = WordTokenizer('latin')
__author__ = ['Patrick J. Burns <patrick@diyclassics.org>', 'Todd Cook <todd.g.cook@gmail.com>']
__license__ = 'MIT License. See LICENSE.'

if os.path.exists(cltk_path + 'latin/model/latin_models_cltk/tokenizers/sentence'):
sent_tokenizer = TokenizeSentence('latin')
else:
punkt_param = PunktParameters()
abbreviations = ['c', 'l', 'm', 'p', 'q', 't', 'ti', 'sex', 'a', 'd', 'cn', 'sp', "m'", 'ser', 'ap', 'n', 'v', 'k', 'mam', 'post', 'f', 'oct', 'opet', 'paul', 'pro', 'sert', 'st', 'sta', 'v', 'vol', 'vop']
punkt_param.abbrev_types = set(abbreviations)
sent_tokenizer = PunktSentenceTokenizer(punkt_param)

# Latin Library
try:
latinlibrary = PlaintextCorpusReader(cltk_path + '/latin/text/latin_text_latin_library',
'.*\.txt',
word_tokenizer=word_tokenizer,
sent_tokenizer=sent_tokenizer,
encoding='utf-8')
pass
except IOError as e:
pass
# print("Corpus not found. Please check that the Latin Library is installed in CLTK_DATA.")
abbreviations = ['c', 'l', 'm', 'p', 'q', 't', 'ti', 'sex', 'a', 'd', 'cn', 'sp', "m'", 'ser',
'ap', 'n', 'v', 'k', 'mam', 'post', 'f', 'oct', 'opet', 'paul', 'pro', 'sert',
'st', 'sta', 'v', 'vol', 'vop']
@@ -0,0 +1,303 @@
"""`latin_library_corpus_types` - a mapping of corpus types into common periods, based largely on:
https://en.wikipedia.org/wiki/Latin_literature
and some personal choices, e.g.: the inscrutable Twelve Tables is placed in an 'early' latin
classification, while Plautus and Terence are in the Old latin section, some uncertain items are
binned into 'misc'. Pull requests to further sort this out are welcome!
"""

texts_to_remove_from_fileids = [
'index.txt',
'indices.txt'
]

# ontology map directories

corpus_directories_by_type = {

'republican': [
'./caesar',
'./lucretius',
'./nepos',
'./cicero'
],
'augustan': [
'./livy',
'./ovid',
'./horace',
'./vergil',
'./hyginus',
],
'early_silver': [
'./martial',
'./juvenal',
'./tacitus',
'./lucan',
'./quintilian',
'./sen',
'./statius',
'./silius',
'./columella'
],
'late_silver': [
'./suetonius',
'./gellius',
'./apuleius'
'./justin',
'./apicius',
'./fulgentius',
'./orosius',
],
'old': [
'./plautus'
],
'christian': [
'./ambrose',
'./abelard',
'./alcuin',
'./augustine',
'./bede',
'./bible',
'./cassiodorus',
'./commodianus',
'./gregorytours',
'./hugo',
'./isidore',
'./jerome',
'./prudentius',
'./tertullian',
'./kempis',
'./leothegreat',
],
'medieval': [
'./boethiusdacia',
'./dante',
],
'renaissance': [
],
'neo_latin': [
'./addison',
'./bacon',
'./bultelius',
'./descartes',
'./erasmus',
'./galileo',
'./kepler',
'./may',
'./melanchthon',
'./xylander',
'./campion',
],
#: uncategorized
'misc':
[
'./alanus',
'./albertanus',
'./albertofaix',
'./aquinas',
'./ammianus',
'./arnobius',
'./capellanus',
'./cato',
'./claudian',
'./curtius',
'./eutropius',
'./frontinus',
'./gestafrancorum',
'./justinian',
'./lactantius',
'./martinbraga',
'./mirandola',
'./ottofreising',
'./pauldeacon',
'./sha',
'./theodosius',
'./voragine',
'./walter',
'./williamtyre'
],
'early': []
}

#### by text


corpus_texts_by_type = {
'republican': [
'sall.1.txt',
'sall.2.txt',
'sall.cotta.txt',
'sall.ep1.txt',
'sall.ep2.txt',
'sall.frag.txt',
'sall.invectiva.txt',
'sall.lep.txt',
'sall.macer.txt',
'sall.mithr.txt',
'sall.phil.txt',
'sall.pomp.txt',
'varro.frag.txt',
'varro.ll10.txt',
'varro.ll5.txt',
'varro.ll6.txt',
'varro.ll7.txt',
'varro.ll8.txt',
'varro.ll9.txt',
'varro.rr1.txt',
'varro.rr2.txt',
'varro.rr3.txt',
'sulpicia.txt',
],
'augustan': [
'resgestae.txt',
'resgestae1.txt',
'manilius1.txt',
'manilius2.txt',
'manilius3.txt',
'manilius4.txt',
'manilius5.txt',
'catullus.txt',
'vitruvius1.txt',
'vitruvius10.txt',
'vitruvius2.txt',
'vitruvius3.txt',
'vitruvius4.txt',
'vitruvius5.txt',
'vitruvius6.txt',
'vitruvius7.txt',
'vitruvius8.txt',
'vitruvius9.txt',
'propertius1.txt',
'tibullus1.txt',
'tibullus2.txt',
'tibullus3.txt',
],
'early_silver': [
'pliny.ep1.txt',
'pliny.ep10.txt',
'pliny.ep2.txt',
'pliny.ep3.txt',
'pliny.ep4.txt',
'pliny.ep5.txt',
'pliny.ep6.txt',
'pliny.ep7.txt',
'pliny.ep8.txt',
'pliny.ep9.txt',
'pliny.nh1.txt',
'pliny.nh2.txt',
'pliny.nh3.txt',
'pliny.nh4.txt',
'pliny.nh5.txt',
'pliny.nhpr.txt',
'pliny.panegyricus.txt',
'petronius1.txt',
'petroniusfrag.txt',
'persius.txt',
'phaedr1.txt',
'phaedr2.txt',
'phaedr3.txt',
'phaedr4.txt',
'phaedr5.txt',
'phaedrapp.txt',
'seneca.contr1.txt',
'seneca.contr10.txt',
'seneca.contr2.txt',
'seneca.contr3.txt',
'seneca.contr4.txt',
'seneca.contr5.txt',
'seneca.contr6.txt',
'seneca.contr7.txt',
'seneca.contr8.txt',
'seneca.contr9.txt',
'seneca.fragmenta.txt',
'seneca.suasoriae.txt',
'valeriusflaccus1.txt',
'valeriusflaccus2.txt',
'valeriusflaccus3.txt',
'valeriusflaccus4.txt',
'valeriusflaccus5.txt',
'valeriusflaccus6.txt',
'valeriusflaccus7.txt',
'valeriusflaccus8.txt',
'valmax1.txt',
'valmax2.txt',
'valmax3.txt',
'valmax4.txt',
'valmax5.txt',
'valmax6.txt',
'valmax7.txt',
'valmax8.txt',
'valmax9.txt',
'vell1.txt',
'vell2.txt',
],
'late_silver': [
],
'old': [
'ter.adel.txt',
'ter.andria.txt',
'ter.eunuchus.txt',
'ter.heauton.txt',
'ter.hecyra.txt',
'ter.phormio.txt',
'andronicus.txt',
'enn.txt',
],
'early': [
'12tables.txt'
],
'medieval': [
'anselmepistula.txt',
'anselmproslogion.txt',
'carm.bur.txt',
],
'christian': [
'anon.martyrio.txt',
'benedict.txt',
'berengar.txt',
'bernardclairvaux.txt',
'bernardcluny.txt',
'bonaventura.itinerarium.txt',
'creeds.txt',
'decretum.txt',
'diesirae.txt',
'egeria.txt',
'ennodius.txt',
'eucherius.txt',
'eugippius.txt',
'greg.txt',
'gregory.txt',
'gregory7.txt',
'hydatius.txt',
'hymni.txt',
'innocent.txt',
'hydatius.txt',
'junillus.txt',
'lactantius.txt',
'liberpontificalis.txt',
'macarius.txt',
'macarius1.txt',
'novatian.txt',
'papal.txt',
'paulinus.poemata.txt',
'perp.txt',
'professio.txt',
'prosperus.txt',
'regula.txt',
'sedulius.txt',
'sulpiciusseverus.txt',
'vorag.txt',
],
'renaissance': [
'petrarch.ep1.txt',
'petrarch.numa.txt',
'petrarch.rom.txt',
],
'neo_latin': [
'spinoza.ethica1.txt',
'spinoza.ethica2.txt',
'spinoza.ethica3.txt',
'spinoza.ethica4.txt',
'spinoza.ethica5.txt'
],
'misc':[]
}
Oops, something went wrong.

0 comments on commit 320e810

Please sign in to comment.