How to use the pythainlp.cli function in pythainlp

To help you get started, we’ve selected a few pythainlp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PyThaiNLP / pythainlp / pythainlp / cli / tokenize.py View on Github external
"--keep-whitespace",
            dest="keep_whitespace",
            action="store_true",
        )
        parser.add_argument(
            "-nw",
            "--no-whitespace",
            dest="keep_whitespace",
            action="store_false",
        )
        parser.set_defaults(keep_whitespace=True)

        args = parser.parse_args(argv)
        self.args = args

        cli.exit_if_empty(args.text, parser)
        result = self.run(
            args.text,
            engine=args.algorithm,
            keep_whitespace=args.keep_whitespace,
        )
        print(args.separator.join(result) + args.separator)
github PyThaiNLP / pythainlp / pythainlp / cli / benchmark.py View on Github external
description=(
                "Benchmark for various tasks;\n"
                "currently, we have only for word tokenization."
            ),
            usage=(
                "thainlp benchmark [task] [task-options]\n\n"
                "tasks:\n\n"
                "word-tokenization      benchmark word tokenization\n\n"
                "--"
            ),
        )

        parser.add_argument("task", type=str, help="[word-tokenization]")

        args = parser.parse_args(argv[2:3])
        cli.exit_if_empty(args.task, parser)
        task = str.lower(args.task)

        task_argv = argv[3:]
        if task == "word-tokenization":
            WordTokenizationBenchmark(task, task_argv)
github PyThaiNLP / pythainlp / pythainlp / cli / corpus.py View on Github external
"--name",
            type=str,
            help="corpus's name",
        )

        parser.add_argument(
            "command",
            type=str,
            default="",
            nargs="?",
            help="[download|remove]"
        )

        args = parser.parse_args(argv[2:])

        cli.exit_if_empty(args.command, parser)
        command = args.command

        if hasattr(App, command):
            getattr(App, command)(args)
        else:
            print("No command available: %s" % command)
github PyThaiNLP / pythainlp / pythainlp / __main__.py View on Github external
args = sys.argv[1:]

    parser = argparse.ArgumentParser(
        "thainlp", usage="thainlp  [options]"
    )

    parser.add_argument(
        "command",
        type=str,
        choices=cli.COMMANDS,
        help="text processing action",
    )

    args = parser.parse_args(sys.argv[1:2])

    cli.exit_if_empty(args.command, parser)

    if hasattr(cli, args.command):
        command = getattr(cli, args.command)
        command.App(sys.argv)
    else:
        print(f"Command not available: {args.command}")
        print("Please run with --help for alternatives")
github PyThaiNLP / pythainlp / pythainlp / __main__.py View on Github external
def main(args=None):
    """ThaiNLP command line."""
    if args is None:
        args = sys.argv[1:]

    parser = argparse.ArgumentParser(
        "thainlp", usage="thainlp  [options]"
    )

    parser.add_argument(
        "command",
        type=str,
        choices=cli.COMMANDS,
        help="text processing action",
    )

    args = parser.parse_args(sys.argv[1:2])

    cli.exit_if_empty(args.command, parser)

    if hasattr(cli, args.command):
        command = getattr(cli, args.command)
        command.App(sys.argv)
    else:
        print(f"Command not available: {args.command}")
        print("Please run with --help for alternatives")