def ner(**kwargs):
kwargs["no_standardize"] = not kwargs["no_standardize"]
kwargs["no_convert_ions"] = not kwargs["no_convert_ions"]
kwargs["no_header"] = not kwargs["no_header"]
kwargs["no_normalize_text"] = not kwargs["no_normalize_text"]
kwargs["no_annotation"] = not kwargs["no_annotation"]
is_output_file = bool(kwargs["output"])
stdin = click.get_text_stream("stdin")
input_text = ""
if not stdin.isatty():
kwargs["input_file"] = ""
input_text = click.get_text_stream("stdin").read().strip()
if not input_text and not kwargs["input_file"]:
raise click.UsageError("Cannot perform NER: stdin is empty and input file is not provided.")
kwargs["opsin_types"] = get_opsin_types(kwargs["opsin_types"])
init_kwargs = get_kwargs(kwargs, KWARGS_CHS_INIT)
process_kwargs = get_kwargs(kwargs, KWARGS_CHS_PROCESS)
chemspot = ChemSpot(**init_kwargs)
result = chemspot.process(input_text=input_text, **process_kwargs)
if kwargs["dry_run"]:
print(result)
exit(0)
if kwargs["raw_output"]:
print(result["stdout"])
eprint(result["stderr"])
exit(0)
if not is_output_file:
print(dict_to_csv(result["content"], csv_delimiter=kwargs["delimiter"], write_header=kwargs["no_header"]))
评论列表
文章目录