Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
):
if require_gpu:
spacy.require_gpu()
print("GPU enabled", file=sys.stderr)
if model_path:
nlp = spacy.load(model_path)
else:
nlp = spacy.load('ja_ginza')
if disable_pipes:
print("disabling pipes: {}".format(disable_pipes), file=sys.stderr)
nlp.disable_pipes(disable_pipes)
print("using : {}".format(nlp.pipe_names), file=sys.stderr)
if recreate_corrector:
if 'JapaneseCorrector' in nlp.pipe_names:
nlp.remove_pipe('JapaneseCorrector')
corrector = JapaneseCorrector(nlp)
nlp.add_pipe(corrector, last=True)
if mode == 'A':
nlp.tokenizer.mode = OriginalTokenizer.SplitMode.A
elif mode == 'B':
nlp.tokenizer.mode = OriginalTokenizer.SplitMode.B
elif mode == 'C':
nlp.tokenizer.mode = OriginalTokenizer.SplitMode.C
else:
raise Exception('mode should be A, B or C')
print("mode is {}".format(mode), file=sys.stderr)
if not use_sentence_separator:
print("disabling sentence separator", file=sys.stderr)
nlp.tokenizer.use_sentence_separator = False
if output_path:
Language.factories['JapaneseCorrector'] = lambda nlp, **cfg: JapaneseCorrector(nlp)