@click.option( "-s", "--skip-existing", default=True, type=click.BOOL, help="Skip over any keys which already exist in the destination file", ) @click.option("-d", "--destination", default="", type=str, help="Destination for serialized environment variables") @click.option("-t", "--template", default=".env.yml", type=click.File(), help="Source for environment and default values") @click.option( "-z", "--zero-input", is_flag=True, help="Skip prompts and use presets verbatim. Useful for CI environments.") @click.version_option(__version__) def barbara_develop(skip_existing, destination, template, zero_input): """Development mode which prompts for user input""" if zero_input: destination = ".env" destination_handler = create_target_file merge_strategy = merge_with_presets else: destination_handler = confirm_target_file
def build_cli_from_cls(model: Type[Model]) -> click.Command: # noqa: D202 """Build a :mod:`click` command line interface for a KGE model. Allows users to specify all of the (hyper)parameters to the model via command line options using :class:`click.Option`. """ signature = inspect.signature(model.__init__) def _decorate_model_kwargs(command: click.Command) -> click.Command: for name, annotation in model.__init__.__annotations__.items(): if name in _SKIP_ARGS or annotation in _SKIP_ANNOTATIONS: continue elif name in CLI_OPTIONS: option = CLI_OPTIONS[name] elif annotation in {Optional[int], Optional[str]}: option = click.option(f'--{name.replace("_", "-")}', type=_OPTIONAL_MAP[annotation]) else: parameter = signature.parameters[name] if annotation in { Hint[Initializer], Hint[Constrainer], Hint[Normalizer] }: # type: ignore logger.debug('Unhandled hint: %s', annotation) continue if parameter.default is None: logger.warning( f'Missing handler in {model.__name__} for {name}: ' f'type={annotation} default={parameter.default}', ) continue option = click.option(f'--{name.replace("_", "-")}', type=annotation, default=parameter.default) try: command = option(command) except AttributeError: logger.warning( f'Unable to handle parameter in {model.__name__}: {name}') continue return command @click.command(help=f'CLI for {model.__name__}', name=model.__name__.lower()) # type: ignore @options.device_option @options.dataset_option @options.training_option @options.testing_option @options.valiadation_option @options.optimizer_option @options.training_loop_option @options.automatic_memory_optimization_option @options.number_epochs_option @options.batch_size_option @options.learning_rate_option @options.evaluator_option @options.stopper_option @options.mlflow_uri_option @options.title_option @options.num_workers_option @options.random_seed_option @_decorate_model_kwargs @click.option('--silent', is_flag=True) @click.option('--output', type=click.File('w'), default=sys.stdout, help='Where to dump the metric results') def main( *, device, training_loop, optimizer, number_epochs, batch_size, learning_rate, evaluator, stopper, output, mlflow_tracking_uri, title, dataset, automatic_memory_optimization, training_triples_factory, testing_triples_factory, validation_triples_factory, num_workers, random_seed, silent: bool, **model_kwargs, ): """CLI for PyKEEN.""" click.echo( f'Training {model.__name__} with ' f'{training_loop.__name__[:-len("TrainingLoop")]} using ' f'{optimizer.__name__} and {evaluator.__name__}', ) from ...pipeline import pipeline result_tracker: Optional[str] result_tracker_kwargs: Optional[Mapping[str, Any]] if mlflow_tracking_uri: result_tracker = 'mlflow' result_tracker_kwargs = { 'tracking_uri': mlflow_tracking_uri, } else: result_tracker = None result_tracker_kwargs = None pipeline_result = pipeline( device=device, model=model, model_kwargs=model_kwargs, dataset=dataset, training=training_triples_factory, testing=testing_triples_factory or training_triples_factory, validation=validation_triples_factory, optimizer=optimizer, optimizer_kwargs=dict(lr=learning_rate, ), training_loop=training_loop, evaluator=evaluator, training_kwargs=dict( num_epochs=number_epochs, batch_size=batch_size, num_workers=num_workers, ), stopper=stopper, result_tracker=result_tracker, result_tracker_kwargs=result_tracker_kwargs, metadata=dict(title=title, ), random_seed=random_seed, automatic_memory_optimization=automatic_memory_optimization, ) if not silent: json.dump(pipeline_result.metric_results.to_dict(), output, indent=2) click.echo('') return sys.exit(0) return main
from pymantic import sparql from concurrent.futures import ThreadPoolExecutor import pyin from pyin import * import rdflib import click import common server, this = None, None default_graph = '<http://kbd.bg/#runs>' pyin.default_graph = default_graph @click.command() @click.argument('kb', type=click.File('rb')) @click.argument('goal', type=click.File('rb')) @click.option('--nokbdbg', default=False) @click.option('--nolog', default=False, type=bool) @click.option('--visualize', default=False) @click.option('--sparql_uri', default='', help='for example http://localhost:9999/blazegraph/sparql') @click.option('--identification', default="") @click.option('--base', default="") def query_from_files(kb, goal, nokbdbg, nolog, visualize, sparql_uri, identification, base): global server, this pyin.kbdbg_file_name, pyin._rules_file_name, pyin.rules_jsonld_file_name, identification, base, this, runs_path = set_up(identification, base) pyin.this = this pyin.nolog = nolog common.nolog = nolog pyin.init_logging()
yield from yield_gilda('chebi', chebi_id, name, suffix, search_text, show_missing) else: for _suffix in SUFFIXES: if name.endswith(_suffix): search_text = name[:-len(_suffix)].rstrip() yield from yield_gilda('chebi', chebi_id, name, _suffix, search_text, show_missing) break @click.command() @verbose_option @click.option('--show-ungrounded', is_flag=True) @click.option('--output', type=click.File('w'), default=os.path.join(RESOURCES_DIRECTORY, 'uncurated_chebi.tsv')) def main(show_ungrounded: bool, output: Optional[TextIO]) -> None: """Run the ChEBI curation pipeline.""" sort_xrefs_df() # suggest_activator_curation() # suggest_pathway_inhibitor_curation() # suggest_inhibitor_curation() # suggest_agonist_curation() # suggest_antagonist_curation() # suggest_inverse_agonist_curation() # propose_enzyme_modulators() suggest_all_roles(show_ungrounded=show_ungrounded or output is not None, file=output)
@benchmark.command(name="list", short_help="List benchmark suite") @click.option("--src", metavar="<arrow_src>", show_default=True, default=ArrowSources.find(), callback=validate_arrow_sources, help="Specify Arrow source directory") @click.option("--preserve", type=bool, default=False, show_default=True, is_flag=True, help="Preserve workspace for investigation.") @click.option("--output", metavar="<output>", type=click.File("w", encoding="utf8"), default="-", help="Capture output result into file.") @click.option("--cmake-extras", type=str, multiple=True, help="Extra flags/options to pass to cmake invocation. " "Can be stacked") @click.argument("rev_or_path", metavar="[<rev_or_path>]", default="WORKSPACE", required=False) @click.pass_context def benchmark_list(ctx, src, preserve, output, cmake_extras, rev_or_path): """ List benchmark suite. """
with BytesIO() as b: txn.stream(b) psbt.txn = b.getvalue() out_psbt.write(psbt.as_bytes()) print("PSBT to be signed:\n\n\t" + out_psbt.name, end='\n\n') @click.group() @click.option('-p', '--payout_address', type=str, default=None, metavar="1bitcoinaddr") @click.option('-o', '--output_psbt', type=click.File('wb'), default="out.psbt") @click.option('-t', '--testnet', help="Assume testnet3 addresses", is_flag=True, default=False) @click.pass_context def cli(ctx, payout_address, output_psbt, testnet): ctx.ensure_object(dict) ctx.obj['payout_address'] = payout_address ctx.obj['output_psbt'] = output_psbt global TESTNET TESTNET = testnet
from pprint import pprint as pp import click @click.command() @click.argument("gene-list", type=click.File("r")) @click.option("--panel-name", "-n", required=True) @click.pass_context def cli(ctx, gene_list, panel_name): # Dictionary with panel_id as key panel_metadata = {} header = [] panel_genes = {} for line in gene_list: line = line.rstrip() if line.startswith("#"): if line.startswith("##"): # These headers include metainformation about the panels or # contig information which we are not interested in. # They allways start with Database=<ID=<some_name> and are # ',' separated. if not "contig" in line: panel_info = {} line = line.split(",") panel_info["institute"] = line[0][15:22] for entry in line[1:]: splitted_entry = entry.split("=") key = splitted_entry[0] value = splitted_entry[1] if key == "Version":
import configparser import click import sys @click.command() @click.argument('configfile', type=click.File('rb')) @click.argument('section') @click.argument('option') @click.option('-e', '--encoding', default='utf-8') def extract_from_inifile(configfile, section, option, encoding): # click opens a file ready to be read so # read the configfile into a config parser # with the specified encoding try: config = configparser.ConfigParser() config.read_string(configfile.read().decode(encoding)) result = config.get(section, option) click.echo(result) except configparser.Error as e: # If we get an error opening the file then # print it to stderr click.echo('Error: {}'.format(e), err=True) sys.exit()
MEMORY_ID - id/index of the memory (default: 0) """ with McuBoot(ctx.obj['interface']) as mboot: response = mboot.get_property(property_tag, index=index) # type: ignore assert response, f"Error reading property {property_tag}" display_output(response, mboot.status_code, ctx.obj['use_json'], parse_property_value(property_tag, response)) @main.command() @click.argument('address', type=INT(), required=True) @click.argument('byte_count', type=INT(), required=True) @click.argument('out_file', metavar='FILE', type=click.File('wb'), required=False) @click.argument('memory_id', type=int, default=0, required=False) @click.option('-h', '--use-hexdump', is_flag=True, default=False, help='Use hexdump format') @click.pass_context def read_memory(ctx: click.Context, address: int, byte_count: int, out_file: click.File, memory_id: int, use_hexdump: bool) -> None: """Read memory. \b ADDRESS - starting address
app = Datasette([], plugins_dir=plugins_dir) click.echo(json.dumps(app.plugins(all), indent=4)) @cli.command() @click.argument("files", type=click.Path(exists=True), nargs=-1, required=True) @click.option( "-t", "--tag", help= "Name for the resulting Docker container, can optionally use name:tag format", ) @click.option( "-m", "--metadata", type=click.File(mode="r"), help="Path to JSON/YAML file containing metadata to publish", ) @click.option("--extra-options", help="Extra options to pass to datasette serve") @click.option("--branch", help="Install datasette from a GitHub branch e.g. master") @click.option( "--template-dir", type=click.Path(exists=True, file_okay=False, dir_okay=True), help="Path to directory containing custom templates", ) @click.option( "--plugins-dir", type=click.Path(exists=True, file_okay=False, dir_okay=True), help="Path to directory containing custom plugins",
raise click.UsageError( "Illegal usage: '" + str(self.name) + "' is mutually exclusive with " + str(mutex_opt) + ".") else: self.prompt = None return super(Mutex, self).handle_parse_result(ctx, opts, args) def validate_batch_size(ctx, param, value): if value < 1: raise click.BadParameter('Invalid batch size.') return value @click.command(name='exporter') @click.version_option(version='1.0.0') @click.option('-c', '--config', type=click.File(mode='r'), callback=load_config_file, help='File containing GitHub and GitLab tokens.', required=True) @click.option('--export-all', is_flag=True, default=False, help='Export all GitLab projects associated with given token.') @click.option('-p', '--projects', type=click.File(mode='r', lazy=True), callback=load_projects_file, cls=Mutex, help='Project names to export. See Documentation for format.', not_required_if=['export-all']) @click.option('--purge-gh', default=False, show_default=False, is_flag=True, is_eager=True, expose_value=False, callback=delete_all_github_repos, help='Prompt for GitHub token with admin access, delete all repos and exit. Dangerous!') @click.option('--debug', default=False, is_flag=True, help='Run application in debug mode. Application is unstable in this mode.') @click.option('--conflict-policy', type=click.Choice(['skip', 'overwrite']), default='skip', help='[skip] skip export for project names which already exists on GitHib.' '[overwrite] overwrite any GitHub project which already exists.') @click.option('--tmp-dir', type=click.Path(), help='Temporary directory to store data during export.', default='tmp', show_default=True)
for cur_job in job_list: job_start_char, job_end_char = \ [int((x - overall_start) / overall_span * max_num_of_chars) for x in (cur_job.starttime, cur_job.endtime)] s = '{0:6d}: |{1}{2}{3}|'.format(cur_job.seq, space * job_start_char, fill * (job_end_char - job_start_char), space * (max_num_of_chars - job_end_char)) click.echo(s) @click.command() @click.version_option(version=__version__) @click.argument('input_file', type=click.File('rt')) @click.option('-w', '--width', default=80, type=int, metavar='NUM', help='Maximum number of characters to use for the bars', show_default=True) @click.option('-s', '--sort', 'ordering', default='seq', metavar='FIELD', help='Specify how jobs should be ordered. Possible values ' 'are "seq", "starttime", "endtime", and "runtime"', show_default=True) @click.option('--space', default=DEFAULT_SPACE, metavar='CHAR', help='Character to use for the plot background') @click.option('--fill', default=DEFAULT_FILL, metavar='CHAR', help='Character to use for the plot bars', show_default=True) def main(input_file, width, ordering, space, fill): sort_dict = {'seq': lambda x: x.seq,
} with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) async def run_in_executor(sync_func, *params): loop = asyncio.get_running_loop() return await loop.run_in_executor(None, sync_func, *params) async def async_main(playlist_file): urls = [] if playlist_file: urls.extend(get_playlist(playlist_file)) tasks = [run_in_executor(download_video, url) for url in urls] for future in tqdm(asyncio.as_completed(tasks), total=len(tasks)): await future @click.command() @click.argument('playlist_file', type=click.File('r')) def main(playlist_file): asyncio.run(async_main(playlist_file)) if __name__ == '__main__': main()
import click from aiida.cmdline.params import options from aiida.cmdline.utils import decorators, echo from . import cmd_data @cmd_data.group('structure') def cmd_structure(): """Commands to create and inspect `StructureData` nodes.""" @cmd_structure.command('import') @click.argument('filename', type=click.File('r')) @options.DRY_RUN() @decorators.with_dbenv() def cmd_import(filename, dry_run): """Import a `StructureData` from a Quantum ESPRESSO input file.""" from aiida_quantumespresso.tools.pwinputparser import PwInputFile parser = PwInputFile(filename) structure = parser.get_structuredata() formula = structure.get_formula() if dry_run: echo.echo_success('parsed structure with formula {}'.format(formula)) else: structure.store() echo.echo_success(
import os from click import ClickException from docxtpl import DocxTemplate from docxtpl.parsers import PARSERS def parse_variable_file(file): try: file_extension = os.path.splitext(file.name)[1] return PARSERS[file_extension](file) except AttributeError: return dict() except KeyError: error = "Unkown variable file extension '{}'" raise ClickException(error.format(file_extension)) @click.command(context_settings=dict( help_option_names=["-h", "--help"], ignore_unknown_options=True, )) @click.argument("template") @click.option("--verbose", "-V", is_flag=True) @click.option("--variables", "-v", type=click.File("rb"), help="Read template variables from FILENAME. Built-in parsers are JSON, YAML, TOML and XML.") @click.option("--output", "-o", help="output file") def cli(template,variables,output,v): doc = DocxTemplate(template) context = dict() for f in variables: context.update(parse_variable_file(f)) doc.render(context) doc.save(output)
_ORDERING_TEXT = ', '.join( f'{i}) {x}' for i, x in enumerate(DEFAULT_PRIORITY_LIST, start=1)) @main.command(help=f'Prioritize a CURIE from ordering: {_ORDERING_TEXT}') @click.argument('curie') def prioritize(curie: str): """Prioritize a CURIE.""" priority_curie = get_priority_curie(curie) click.secho(priority_curie) @main.command() @click.option('-i', '--file-in', type=click.File('r'), default=sys.stdin) @click.option('-o', '--file-out', type=click.File('w'), default=sys.stdout) @click.option('--column', type=int, default=0, show_default=True) @click.option('--sep', default='\t', show_default=True) def recurify(file_in, file_out, column: int, sep: str): """Remap a column in a given file stream.""" remap_file_stream(file_in=file_in, file_out=file_out, column=column, sep=sep) @main.command() @verbose_option def cache(): """Cache all resources."""
import json import re import click import jsonschema import utils @click.command() @click.argument('schema', type=click.File('r'), required=True) @click.argument('jsonfiles', type=click.Path(exists=True), required=True) def validate_path(schema, jsonfiles): schema = json.loads(schema.read()) for path in utils.get_files(jsonfiles): path_components = utils.get_path_parts(path) regex = schema[path_components[0]] if not re.compile(regex).match(path): raise AssertionError('Path "%s" does not match spec "%s"' % (path, regex)) if __name__ == '__main__': validate_path()
key, value = value.split('=', 1) if not self.re_pattern.match(key): self.fail('%s is not a valid identifier' % key) except ValueError: self.fail('%s is not a valid key/value string' % value, param, ctx) return (key, value) class Connection(object): def __init__(self): self.ecs = boto3.client('ecs') @click.command() @click.option('--config', required=True, type=click.File()) @click.option('--var', multiple=True, type=VarType()) @click.option('--dry-run', is_flag=True, default=False) @click.option('--output-path', required=False, type=click.Path()) def main(config, var, output_path, dry_run): base_path = os.path.dirname(config.name) config = yaml.load(config) template_vars = dict(var) connection = Connection() cluster_name = config['cluster_name'] services = config['services'] logger.info("Starting deploy on cluster %s (%s services)", cluster_name, len(services)) # Generate the task definitions
except TypeError: return None if pad_len > len(plaintext): return None return plaintext[:-pad_len] @click.group(help="Encode and decode mylogin.cnf files.") def coder(): pass @coder.command() @click.argument("infile", envvar="MYSQL_TEST_LOGIN_FILE", type=click.File("rb")) @click.argument("outfile", type=click.File("wb", atomic=True)) def decode(infile, outfile): """ Decode infile into outfile """ (version,) = struct.unpack("i", infile.read(_VERSION_LENGTH)) key = bytearray(infile.read(_LOGIN_KEY_LENGTH)) real_key = realkey(key) while rlen := infile.read(_CIPHERTEXT_LENGTH): (len,) = struct.unpack("I", rlen) ciphertext = infile.read(len) line = decode_line(ciphertext, real_key) outfile.write(line)
logging.basicConfig(level=logging.INFO) start, end = get_dates(start, end, tz) all_resources = [] for rtype_name in resources: rtype = Resource.get_type(rtype_name) resources = rtype.get_resources(cmdb, start, end, app, env) all_resources.extend(resources) print(json.dumps(all_resources, indent=2)) @cli.command('load-resources') @click.option('--bucket', required=True, help="Config Bucket") @click.option('--prefix', required=True, help="Config Bucket Prefix") @click.option('--region', required=True, help="Load Config for Region") @click.option('--account-config', type=click.File('rb'), required=True) @click.option('-a', '--accounts', multiple=True) @click.option('--assume', help="Assume role") @click.option('--start') @click.option('--end') @click.option('-r', '--resources', multiple=True, type=click.Choice(list(RESOURCE_FILE_INDEXERS.keys()))) @click.option('--store', type=click.Path()) @click.option('-f', '--db') @click.option('-v', '--verbose', is_flag=True) @click.option('--debug', is_flag=True) def load_resources(bucket, prefix, region, account_config, accounts, assume, start, end, resources, store, db, verbose, debug): """load resources into resource database."""
""" Gets an empty nodegroup in EKS-dict format that only has the Cortex nodegroup name filled out. """ return {"name": name} def get_ami(ami_map: dict, instance_type: str) -> str: if is_gpu(instance_type) or is_inf(instance_type): return ami_map["accelerated_amd64"] if is_arm64(instance_type): return ami_map["cpu_arm64"] return ami_map["cpu_amd64"] @click.command() @click.argument("cluster-config_file", type=click.File("r")) @click.argument("ami-json-file", type=click.File("r")) @click.option( "--add-cortex-node-groups", type=str, help= "specific cortex nodegroups to add to the generated eks file; use this for existing clusters", ) @click.option( "--remove-eks-node-groups", type=str, help= "specific eks nodegroup stacks to add to the generated eks file; use this for existing clusters", ) def generate_eks(cluster_config_file, ami_json_file, add_cortex_node_groups: str, remove_eks_node_groups: str):
logging.error("Uncaught exception in worker process:\n" f"{exc_buffer.getvalue()}") raise e @cli.group() def store(): """Inspect or manipulate the records and data stores.""" pass # TODO?: Alias datastore, recordstore group commands ? @store.command() @click.argument('taskdesc', nargs=1, type=click.File()) def find_output(taskdesc): # NB: Use `find-output` on CLI """ Find output files for a previously run TASKDESC. If the specified task was not already run, or not recorded, prints a message stating that no task output was found. """ task = Task.from_desc(taskdesc.read()) try: found_files = task.find_saved_outputs() except FileNotFoundError: print(f"No task output found for task {task.name}.") else: print(f"Outputs for task {task.name}:") if found_files.is_partial:
totals['name'] = '' writer = csv.DictWriter(fh, fieldnames=field_names, extrasaction='ignore') writer.writerow(dict(zip(field_names, field_names))) writer.writerow(totals) for b in buckets: bd = {n: getattr(b, n) for n in field_names} writer.writerow(bd) @cli.command() @click.option('--dbpath', '-f', help="json stats db") @click.option('--output', '-o', type=click.File('wb'), default='-', help="file to to output to (default stdout)") @click.option('--format', help="format for output", type=click.Choice(['plain', 'csv']), default='plain') @click.option('--bucket', '-b', help="stats on a particular bucket", multiple=True) @click.option('--account', '-a', help="stats on a particular account", multiple=True) @click.option('--matched', is_flag=True, help="filter to buckets with matches")
data.update( dict( commit=None, modified=None, author=None, source=None, )) violations.insert(data) inserted += 1 lines_bar.update(1) return inserted @cli.command() @click.argument('reports', nargs=-1, type=click.File('r')) def read(reports): """Read a pylint report into the database.""" violations = get_table() for report in reports: inserted = read_report(violations, report) click.echo(f"Inserted {inserted} violations from {report.name}") def blame_one(file_group): """Run git blame on one file and return the updated rows.""" filename, rows = file_group cmd = ['git', '-C', GIT_DIR, 'blame', '-e'] for row in rows: cmd.extend(["-L", f"{row['lineno']},+1"])
ctx=ctx, renderer=SingularityRenderer, pkg_manager=pkg_manager, **kwds, ) @click.command() @click.argument( "container_type", required=True, type=click.Choice(["docker", "singularity"], case_sensitive=False), ) @click.argument( "input", type=click.File("r"), default=sys.stdin, ) def genfromjson(*, container_type: str, input: ty.IO): """Generate a container from a ReproEnv JSON file. INPUT is standard input by default or a path to a JSON file. """ d = json_lib.load(input) renderer: ty.Type[_Renderer] if container_type.lower() == "docker": renderer = DockerRenderer elif container_type.lower() == "singularity": renderer = SingularityRenderer
def cli(ctx, verbose): if verbose: utils.enable_apdu_log() def get_client(): devices = enumerate_devices() if len(devices) == 0: click.echo("No Ledger device has been found.") sys.exit(0) return LedgerClient(devices[0], private_key=get_private_key()) ctx.obj = get_client @cli.command(help="Send raw data to the device.") @click.argument("input_file", type=click.File("r")) @click.pass_obj def send(get_client, input_file): client = get_client() while True: chunk = input_file.readline() if not chunk: break response = client.raw_exchange(bytes.fromhex(chunk.rstrip())) click.echo(response.hex()) @cli.command(help="Check if device is genuine.") @remote_options @click.pass_obj def genuine_check(get_client, url, key):
# Customizations for: # oci analytics analytics-instance create # # --idcs-access-token replaced by --idcs-access-token-file file paramenter. # --capacity complex type replaced by --capacity-type and --capacity-value # @cli_util.copy_params_from_generated_command( analytics_cli.create_analytics_instance, params_to_exclude=['capacity', 'idcs_access_token']) @analytics_cli.analytics_instance_group.command( name='create', help=analytics_cli.create_analytics_instance.help) @cli_util.option( '--idcs-access-token-file', type=click.File('r'), help= u"""A file containing the IDCS access token identifying a stripe and service administrator user.""" ) @cli_util.option('--capacity-type', required=True, help=u"""The capacity model to use.""") @cli_util.option( '--capacity-value', type=click.INT, required=True, help= u"""The capacity value selected (OLPU count, number of users, ...etc...). This parameter affects the number of CPUs, amount of memory or other resources allocated to the instance.""" ) @click.pass_context @json_skeleton_utils.json_skeleton_generation_handler(
#!/usr/bin/env python3 import os import pickle import yaml import click from main import print_multilabel_results @click.command() @click.option('--result', type=click.File('r'), help='Output of vw') @click.option('--table', type=click.File('r'), help='Table of labels vs. numbers') @click.option('--truth', type=click.File('r'), help='Actual labels') @click.option('--output', type=click.Path(dir_okay=True), help='Folder to output') def score_vw(result, table, truth, output): """ Returns the scores for vw """ label_dict = yaml.load(table) resfile = 'tmp_results.pkl' y_test = [] ntags = [] for line in truth: labels = [x.strip() for x in line.split(' ')] y_test.append(labels) ntags.append(len(labels)) preds = []
gold_columns = [] for header in headers: # Add gold answer columns for each chunk if re.search('chunk_[0-9]{2}$', header): gold_columns.append(header + '_gold') headers += gold_columns headers.sort() logger.debug('CSV headers: %s' % headers) writer = DictWriter(outfile, headers) writer.writeheader() writer.writerows(data_units) return 0 @click.command() @click.argument('frame_data', type=click.File()) @click.argument('sentences_data', type=click.File()) @click.option('--filter-places', '-f', is_flag=True, default=False) @click.option('--outfile', '-o', type=click.File('w'), default='output/crowdflower_input.csv') def main(frame_data, sentences_data, outfile, filter_places): """ Build the CSV input data for a CrowdFlower annotation job """ if filter_places: logger.info("Will filter chunks that are typed as places ...") logger.info("Loading frame data from '%s' ..." % frame_data.name) frames = json.load(frame_data) # Need to keep all sentences data in memory, as we need them to shape the CSV sentences = [] logger.info("Loading sentences data from '%s ..." % sentences_data.name)
] @click.command() @click.argument( "gold_file", type=click_pathlib.Path(resolve_path=True, exists=True, dir_okay=False), ) @click.argument( "syst_files", type=click_pathlib.Path(resolve_path=True, exists=True, dir_okay=False), nargs=-1, ) @click.option( "--out_file", type=click.File("w"), default="-", ) @click.option("--onlyf", is_flag=True) @click.option("--metric", "metrics", multiple=True, default=CONLL_METRICS) def make_csv_summary( syst_files: Iterable[pathlib.Path], gold_file: pathlib.Path, out_file: TextIO, onlyf: bool, metrics: List[str], ): gold_conllu = evaluator.load_conllu_file(gold_file) if onlyf: header = ["name", *metrics]