def run(args): if (args.glottolog or args.concepticon) and Catalog is None: # pragma: no cover print( 'To use reference catalogs you must install the cldfcatalog package!' ) return 10 if args.cldf: # pragma: no cover args.cldf = Dataset.from_metadata(args.cldf) with contextlib.ExitStack() as stack: if not args.prime_cache_only: stack.enter_context( db.FreshDB.from_settings(args.settings, log=args.log)) stack.enter_context(SessionContext(args.settings)) for name in ['concepticon', 'glottolog']: if getattr(args, name): # pragma: no cover if getattr(args, name + '_version'): stack.enter_context( Catalog(getattr(args, name), tag=getattr(args, name + '_version'))) else: setattr(args, name, pathlib.Path(getattr(args, name))) if not args.prime_cache_only: with transaction.manager: if args.initializedb: # pragma: no cover args.initializedb.main(args) if hasattr(args.initializedb, 'prime_cache'): with transaction.manager: # pragma: no cover args.initializedb.prime_cache(args)
def run(args): with contextlib.ExitStack() as stack: if args.glottolog_version: # pragma: no cover stack.enter_context( Catalog(args.glottolog, tag=args.glottolog_version)) glottolog.update(args.repos, args.glottolog, str(datetime.date.today().year), "Glottolog {0}".format(args.glottolog_version))
def main(args): gl_dir = PROJECT_DIR.parent / 'glottolog' / 'glottolog' gl_dir = pathlib.Path( input('Path to clone of glottolog/glottolog [{}]: '.format(gl_dir)) or gl_dir) assert gl_dir.exists() with Catalog(gl_dir, tag=input('Glottolog version: ') or None) as cat: _main(Data(), Glottolog(gl_dir))
def _main(commands, args=None, catch_all=False, parsed_args=None, log=None, test=False): try: repos = Config.from_file().get_clone('glottolog') except KeyError: # pragma: no cover repos = pathlib.Path('.') parser, subparsers = get_parser_and_subparsers('glottolog') parser.add_argument('--repos', help="clone of glottolog/glottolog", default=repos, type=pathlib.Path) parser.add_argument( '--repos-version', help="version of repository data. Requires a git clone!", default=None) parser.add_argument('--pkg-dir', help=argparse.SUPPRESS, default=pathlib.Path(__file__).parent) register_subcommands(subparsers, commands) args = parsed_args or parser.parse_args(args=args) args.test = test if not hasattr(args, "main"): parser.print_help() return 1 with contextlib.ExitStack() as stack: if not log: # pragma: no cover stack.enter_context(Logging(args.log, level=args.log_level)) else: args.log = log if args.repos_version: # pragma: no cover # If a specific version of the data is to be used, we make # use of a Catalog as context manager: stack.enter_context(Catalog(args.repos, tag=args.repos_version)) try: args.repos = Glottolog(args.repos) except Exception as e: print(e) return _main(commands, args=[args._command, '-h']) args.log.info('glottolog/glottolog at {0}'.format(args.repos.repos)) try: return args.main(args) or 0 except KeyboardInterrupt: # pragma: no cover return 0 except ParserError as e: print(e) return _main(commands, args=[args._command, '-h']) except Exception as e: # pragma: no cover if catch_all: print(e) return 1 raise
def run(args): cldf = StructureDataset.in_dir(args.cldf_repos / 'cldf') if args.glottolog_version != 'test': # pragma: no cover with Catalog(args.glottolog, args.glottolog_version) as glottolog: write_metadata(cldf, args, glottolog) else: write_metadata(cldf, args, None) write_schema(cldf) cldf.write(**get_data(cldf, args)) shutil.copy(str(args.repos.path('LICENSE.txt')), str(args.cldf_repos)) if not args.dev: cldf.validate(log=args.log)
def main(args=None, catch_all=False, parsed_args=None): try: # pragma: no cover repos = Config.from_file().get_clone('concepticon') except KeyError: # pragma: no cover repos = pathlib.Path('.') parser, subparsers = get_parser_and_subparsers('norare') parser.add_argument('--repos', help="clone of concepticon/concepticon-data", default=repos, type=PathType(type='dir')) parser.add_argument( '--repos-version', help="version of repository data. Requires a git clone!", default=None) parser.add_argument('--norarepo', default=pathlib.Path('.'), type=PathType(type='dir')) register_subcommands(subparsers, pynorare.commands) args = parsed_args or parser.parse_args(args=args) if not hasattr(args, "main"): # pragma: no cover parser.print_help() return 1 with contextlib.ExitStack() as stack: stack.enter_context(Logging(args.log, level=args.log_level)) if args.repos_version: # pragma: no cover # If a specific version of the data is to be used, we make # use of a Catalog as context manager: stack.enter_context(Catalog(args.repos, tag=args.repos_version)) args.repos = Concepticon(args.repos) args.api = NoRaRe(args.norarepo, concepticon=args.repos) args.log.info('norare at {0}'.format(args.repos.repos)) try: return args.main(args) or 0 except KeyboardInterrupt: # pragma: no cover return 0 except ParserError as e: # pragma: no cover print(e) return main([args._command, '-h']) except Exception as e: # pragma: no cover if catch_all: # pragma: no cover print(e) return 1 raise
def run(args): if args.glottolog_version: # pragma: no cover with Catalog(args.glottolog, args.glottolog_version) as glottolog: run_(args, glottolog.dir) else: # pragma: no cover run_(args, args.glottolog)
wals = pycldf.StructureDataset.from_metadata(data / "StructureDataset-metadata.json") coding: t.Dict[int, str] = {} for code in wals["CodeTable"]: if code["Parameter_ID"] != "81A": continue coding[code["ID"]] = code["Name"] missearched = { "Albanian": "alba1267", } print("Accessing Glottolog…") languoids: t.Dict[Language_ID, t.Optional[pyglottolog.languoids.Languoid]] = {} # Activate a specific version of Glottolog with Catalog.from_config("glottolog", tag="v4.3") as glottolog_repo: glottolog = pyglottolog.Glottolog(glottolog_repo.dir) build_langs_index(glottolog, logging) languoids_by_code = glottolog.languoids_by_code() print("Getting macroareas from WALS supplemented by Glottolog…") for language in tqdm(wals["LanguageTable"], total=wals["LanguageTable"].common_props["dc:extent"]): languoids[language["ID"]] = languoids_by_code.get(missearched.get(language["Name"])) if languoids[language["ID"]] is None and language["Glottocode"]: try: languoids[language["ID"]] = languoids_by_code.get(language["Glottocode"]) except (AttributeError, IndexError): pass if languoids[language["ID"]] is None: n, langs = search_langs(glottolog, language["Name"]) if n >= 1: