mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
Suppress convert output if writing to stdout (#4472)
This commit is contained in:
parent
692d7f4291
commit
8d3de90bc4
|
@ -57,7 +57,8 @@ def convert(
|
|||
is written to stdout, so you can pipe them forward to a JSON file:
|
||||
$ spacy convert some_file.conllu > some_file.json
|
||||
"""
|
||||
msg = Printer()
|
||||
no_print = (output_dir == "-")
|
||||
msg = Printer(no_print=no_print)
|
||||
input_path = Path(input_file)
|
||||
if file_type not in FILE_TYPES:
|
||||
msg.fail(
|
||||
|
@ -102,6 +103,7 @@ def convert(
|
|||
use_morphology=morphology,
|
||||
lang=lang,
|
||||
model=model,
|
||||
no_print=no_print,
|
||||
)
|
||||
if output_dir != "-":
|
||||
# Export data to a file
|
||||
|
|
|
@ -9,7 +9,7 @@ from ...tokens.doc import Doc
|
|||
from ...util import load_model
|
||||
|
||||
|
||||
def conll_ner2json(input_data, n_sents=10, seg_sents=False, model=None, **kwargs):
|
||||
def conll_ner2json(input_data, n_sents=10, seg_sents=False, model=None, no_print=False, **kwargs):
|
||||
"""
|
||||
Convert files in the CoNLL-2003 NER format and similar
|
||||
whitespace-separated columns into JSON format for use with train cli.
|
||||
|
@ -34,7 +34,7 @@ def conll_ner2json(input_data, n_sents=10, seg_sents=False, model=None, **kwargs
|
|||
. O
|
||||
|
||||
"""
|
||||
msg = Printer()
|
||||
msg = Printer(no_print=no_print)
|
||||
doc_delimiter = "-DOCSTART- -X- O O"
|
||||
# check for existing delimiters, which should be preserved
|
||||
if "\n\n" in input_data and seg_sents:
|
||||
|
|
|
@ -8,7 +8,7 @@ from ...util import minibatch
|
|||
from .conll_ner2json import n_sents_info
|
||||
|
||||
|
||||
def iob2json(input_data, n_sents=10, *args, **kwargs):
|
||||
def iob2json(input_data, n_sents=10, no_print=False, *args, **kwargs):
|
||||
"""
|
||||
Convert IOB files with one sentence per line and tags separated with '|'
|
||||
into JSON format for use with train cli. IOB and IOB2 are accepted.
|
||||
|
@ -20,7 +20,7 @@ def iob2json(input_data, n_sents=10, *args, **kwargs):
|
|||
I|PRP|O like|VBP|O London|NNP|I-GPE and|CC|O New|NNP|B-GPE York|NNP|I-GPE City|NNP|I-GPE .|.|O
|
||||
I|PRP|O like|VBP|O London|NNP|B-GPE and|CC|O New|NNP|B-GPE York|NNP|I-GPE City|NNP|I-GPE .|.|O
|
||||
"""
|
||||
msg = Printer()
|
||||
msg = Printer(no_print=no_print)
|
||||
docs = read_iob(input_data.split("\n"))
|
||||
if n_sents > 0:
|
||||
n_sents_info(msg, n_sents)
|
||||
|
|
Loading…
Reference in New Issue
Block a user