From 1192d17e86adcdf282d9c18c9a5f0e52eeca47f1 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sun, 18 Oct 2020 22:37:00 +0200 Subject: [PATCH] chg: [download] if a spacy.io model is missing, napkin automatically downloads it Fix #1 TODO: map cld3 language to potential model to be downloaded --- bin/napkin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/napkin.py b/bin/napkin.py index a28e055..6459906 100644 --- a/bin/napkin.py +++ b/bin/napkin.py @@ -27,11 +27,17 @@ parser.add_argument('--disable-tagger', help="disable tagger component in Spacy" parser.add_argument('--token-span', default= None, help='Find the sentences where a specific token is located') parser.add_argument('--table-format', help="set tabulate format (default is fancy_grid)", default="fancy_grid") parser.add_argument('--full-labels', help="store each label value in a ranked set (default is False)", action='store_true', default=False) +#parser.add_argument('--geolocation', help="export geolocation (default is False)", action='store_true', default=False) + args = parser.parse_args() + if args.f is None: parser.print_help() sys.exit() +#if args.geolocation: +# args.full_labels = True + if not args.binary: redisdb = redis.Redis(host="localhost", port=6380, db=5, encoding='utf-8', decode_responses=True) else: @@ -53,8 +59,18 @@ if args.disable_tagger: disable.append("tagger") if args.l == "fr": + try : + nlp = spacy.load("fr_core_news_md", disable=disable) + except: + print("Downloading missing model") + spacy.cli.download("en_core_web_md") nlp = spacy.load("fr_core_news_md", disable=disable) elif args.l == "en": + try: + nlp = spacy.load("en_core_web_md", disable=disable) + except: + print("Downloading missing model") + spacy.cli.download("en_core_web_md") nlp = spacy.load("en_core_web_md", disable=disable) else: sys.exit("Language not supported")