diff --git a/setup.cfg b/setup.cfg index 4022987..f971cb9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,10 @@ install_requires = wget fasttext +[options.entry_points] +console_scripts = + freestylo = freestylo.freestylo_main:main + [options.packages.find] where = src exclude = diff --git a/src/freestylo/freestylo_main.py b/src/freestylo/freestylo_main.py index 6285bb0..e9d9937 100644 --- a/src/freestylo/freestylo_main.py +++ b/src/freestylo/freestylo_main.py @@ -38,19 +38,35 @@ def main(): parser.add_argument("--config", help="Configuration file") args = parser.parse_args() + print("Loading text from", args.input) + print("Loading configuration from", args.config) + print("Saving results to", args.output) + + print("Loading config...") # load config with open(args.config) as f: config = json.load(f) + print("Done") + + max_length = None + if "nlp_max_length" in config: + max_length = config["nlp_max_length"] + + # Load text + print("Loading text...") text = to.TextObject( textfile = args.input, language=config["language"]) + print("Done") # Preprocess text - preprocessor = tp.TextPreprocessor(language=config["language"]) + print("Preprocessing text...") + preprocessor = tp.TextPreprocessor(language=config["language"], max_length=max_length) preprocessor.process_text(text) + print("Done") # Annotate annotation_dict = config["annotations"] for annotation in annotation_dict: @@ -60,63 +76,93 @@ def main(): add_metaphor_annotation(text, annotation_dict[annotation]) elif annotation == "epiphora": add_epiphora_annotation(text, annotation_dict[annotation]) + elif annotation == "polysyndeton": + add_polysyndeton_annotation(text, annotation_dict[annotation]) + elif annotation == "alliteration": + add_alliteration_annotation(text, annotation_dict[annotation]) + text.serialize(args.output) + print("Added all annotations") # Serialize results + print("Serializing results") text.serialize(args.output) + print("Done") + + + print("Finished") def add_chiasmus_annotation(text, config): """ This function adds chiasmus annotations to the text. """ + print("Adding chiasmus annotation") chiasmus = ca.ChiasmusAnnotation( text=text, window_size = config["window_size"]) chiasmus.allowlist = config["allowlist"] chiasmus.denylist = config["denylist"] + print("Finding candidates") chiasmus.find_candidates() + print("Loading model") chiasmus.load_classification_model(config["model"]) + print("Scoring candidates") chiasmus.score_candidates() + print("Done") def add_metaphor_annotation(text, config): """ This function adds metaphor annotations to the text. """ + print("Adding metaphor annotation") metaphor = ma.MetaphorAnnotation(text) + print("Finding candidates") metaphor.find_candidates() + print("Loading model") metaphor.load_model(config["model"]) + print("Scoring candidates") metaphor.score_candidates() + print("Done") def add_epiphora_annotation(text, config): """ This function adds epiphora annotations to the text. """ + print("Adding epiphora annotation") epiphora = ea.EpiphoraAnnotation( text = text, min_length = config["min_length"], conj = config["conj"], punct_pos = config["punct_pos"]) + print("Finding candidates") epiphora.find_candidates() + print("Done") def add_polysyndeton_annotation(text, config): """ This function adds polysyndeton annotations to the text. """ + print("Adding polysyndeton annotation") polysyndeton = pa.PolysyndetonAnnotation( text = text, min_length = config["min_length"], conj = config["conj"], sentence_end_tokens = config["sentence_end_tokens"]) + print("Finding candidates") polysyndeton.find_candidates() + print("Done") def add_alliteration_annotation(text, config): """ This function adds alliteration annotations to the text. """ + print("Adding alliteration annotation") alliteration = aa.AlliterationAnnotation( text = text, max_skip = config["max_skip"], min_length = config["min_length"]) + print("Finding candidates") alliteration.find_candidates() + print("Done") if __name__ == '__main__': main()