Skip to content

Commit 2324db5

Browse files
committed
Add arguments to provide custom training data to gibberish detector training #2402
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent adc3c47 commit 2324db5

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

src/textcode/train_gibberish_model.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,43 @@
1313
from textcode.gibberish import Gibberish
1414

1515
@click.command(name='scancode-train-gibberish-model')
16+
@click.option(
17+
'--big',
18+
type=click.Path(exists=True, readable=True, dir_okay=False, resolve_path=True, path_type=str),
19+
default=None,
20+
help='Text file containing main training corpus for the gibberish detector',
21+
cls=PluggableCommandLineOption,
22+
)
23+
@click.option(
24+
'--good',
25+
type=click.Path(exists=True, readable=True, dir_okay=False, resolve_path=True, path_type=str),
26+
default=None,
27+
help='Text file containing text considered to be not gibberish (good)',
28+
cls=PluggableCommandLineOption,
29+
)
30+
@click.option(
31+
'--bad',
32+
type=click.Path(exists=True, readable=True, dir_okay=False, resolve_path=True, path_type=str),
33+
default=None,
34+
help='Text file containing text considered to be gibberish (bad)',
35+
cls=PluggableCommandLineOption,
36+
)
1637
@click.help_option('-h', '--help')
17-
def train_gibberish_model(*args, **kwargs,):
38+
def train_gibberish_model(big, good, bad, *args, **kwargs,):
1839
"""Train model used by textcode.Gibberish to detect gibberish"""
40+
gibberish_detector_train_args = {}
41+
if big:
42+
gibberish_detector_train_args["bigfile"] = big
43+
if good:
44+
gibberish_detector_train_args["goodfile"] = good
45+
if bad:
46+
gibberish_detector_train_args["badfile"] = bad
47+
1948
click.echo('Training gibberish detector model...')
2049
gibberish_detector = Gibberish()
21-
gibberish_detector.train()
50+
gibberish_detector.train(
51+
**gibberish_detector_train_args
52+
)
2253

2354

2455
if __name__ == '__main__':

0 commit comments

Comments
 (0)