|
13 | 13 | from textcode.gibberish import Gibberish |
14 | 14 |
|
15 | 15 | @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 | +) |
16 | 37 | @click.help_option('-h', '--help') |
17 | | -def train_gibberish_model(*args, **kwargs,): |
| 38 | +def train_gibberish_model(big, good, bad, *args, **kwargs,): |
18 | 39 | """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 | + |
19 | 48 | click.echo('Training gibberish detector model...') |
20 | 49 | gibberish_detector = Gibberish() |
21 | | - gibberish_detector.train() |
| 50 | + gibberish_detector.train( |
| 51 | + **gibberish_detector_train_args |
| 52 | + ) |
22 | 53 |
|
23 | 54 |
|
24 | 55 | if __name__ == '__main__': |
|
0 commit comments