From 37acabc076148fa8d3c97c323a093274c940ece0 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Sun, 16 Jun 2019 01:00:22 +0200 Subject: [PATCH] able to load pickled structures --- src/syntactic_structure.py | 8 +++++++- src/wani.py | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/syntactic_structure.py b/src/syntactic_structure.py index 31aa60a..b90d7a9 100644 --- a/src/syntactic_structure.py +++ b/src/syntactic_structure.py @@ -1,5 +1,6 @@ from xml.etree import ElementTree import logging +import pickle from component import Component, ComponentType from lemma_features import get_lemma_features @@ -92,7 +93,12 @@ class SyntacticStructure: return [] if matches is None else matches -def build_structures(filename): +def build_structures(args): + filename = args.structures + if args.pickled_structures: + with open(filename, 'rb') as fp: + return pickle.load(fp) + max_num_components = -1 with open(filename, 'r') as fp: et = ElementTree.XML(fp.read()) diff --git a/src/wani.py b/src/wani.py index 9f13196..1ba08c3 100644 --- a/src/wani.py +++ b/src/wani.py @@ -107,8 +107,8 @@ def match_file(words, structures): return matches -def main(structures_file, args): - structures, lemma_msds, max_num_components = build_structures(structures_file) +def main(args): + structures, lemma_msds, max_num_components = build_structures(args) match_store = MatchStore(args) word_stats = WordStats(lemma_msds) @@ -218,11 +218,13 @@ if __name__ == '__main__': help='Tag for separators, usually pc or c', default="pc") parser.add_argument('--parallel', help='Run in multiple processes, should speed things up') + parser.add_argument('--match-to-file', help='Do not use!') + parser.add_argument('--pickled-structures', help='Do not use!', action='store_true') args = parser.parse_args() logging.basicConfig(stream=sys.stderr, level=args.verbose.upper()) start = time.time() - main(args.structures, args) + main(args) logging.info("TIME: {}".format(time.time() - start))