def cmd_line():
    """ Command Line Wrapper Function
    """
    parser = ArgumentParser(description='Sanskrit Parser',
                            usage='%(prog)s [sandhi|vakya|tag]  [options] \n\n Use %(prog)s [sandhi|vakya|tag] --help for further options',
                            add_help=False)

    parser.add_argument('command', help='Subcommand to run',
                        choices=["sandhi", "vakya", "tags"])
    parser.add_argument('--debug', action='store_true')

    # parse_args defaults to [1:] for args, but you need to
    # exclude the rest of the args too, or validation will fail
    args, rest = parser.parse_known_args()

    # Logging
    enable_console_logger(level=logging.INFO)
    if args.debug:
        enable_file_logger(level=logging.DEBUG)
    # else:
    #    enable_file_logger(level=logging.INFO)

    if not hasattr(args, 'command'):
        print('Unrecognized command')
        parser.print_help()
        exit(1)
    # use dispatch pattern to invoke method with same name
    eval(getattr(args, 'command')+"(rest)")
Exemple #2
0
def cmd_line():
    # Logging
    enable_console_logger()
    args = get_args()
    if args.debug:
        enable_file_logger(level=logging.DEBUG)
    logger.info(f"Inputs {args.inputs}")
    for i in args.inputs:
        def _i(x):
            if isinstance(x, list):
                for _x in x:
                    _i(_x)
            else:
                logger.info(f"{x} {x.tags}")
        _i(i)
    logger.info("End Inputs")
    if args.vibhakti:
        if ((len(args.inputs) != 1) or (not isinstance(args.inputs[0], Pratipadika))):  # noqa: F405
            logger.info(f"Need a single pratipadika for vibhaktis, got {len(args.inputs)} inputs, first one of type {type(args.inputs[0])}")
            logger.info("Simplifying")
            r = run_pp(args.inputs, args.verbose)
            logger.debug(f"Output: {[''.join([str(x) for x in y]) for y in r]}")
            assert len(r) == 1, "Got multiple outputs"
            pp = PaninianObject.join_objects(r)
            logger.info(f"Output {pp} {pp.tags}")
        else:
            pp = args.inputs[0]
        r = generate_vibhakti(pp, args.verbose)
        print("Output")
        if args.gen_test:
            rr = [[[y[0].transcoded(DEVANAGARI) for y in va] if len(va) > 1 else va[0][0].transcoded(DEVANAGARI) for va in vi] for vi in r]
            print(f"prAtipadika[\"{str(pp)}\"] = {str(pp)}")
            print(f"viBakti[\"{str(pp)}\"] = [")
            for vi in rr:
                print(f"{vi},")
            print("]")
        else:
            for ix, vi in enumerate(r):
                print(f"{', '.join(['/'.join([''.join([x.transcoded(DEVANAGARI) for x in y]).strip('ред') for y in va]) for va in vi])}")
    else:
        r = run_pp(args.inputs, args.verbose)
        print(f"Output: {[''.join([str(x) for x in y]) for y in r]}")
# -*- coding: utf-8 -*-
# flake8: noqa
from sanskrit_parser import enable_console_logger, enable_file_logger
from sanskrit_parser.base.sanskrit_base import SLP1, DEVANAGARI
import sanskrit_parser.generator.sutra as sutra
from sanskrit_parser.generator.paninian_object import PaninianObject
from sanskrit_parser.generator.prakriya import Prakriya, PrakriyaVakya
from sanskrit_parser.generator.pratyaya import *
from sanskrit_parser.generator.dhatu import *
from sanskrit_parser.generator.pratipadika import *
from conftest import run_test, check_vibhakti, generate_vibhakti, test_prakriya
from vibhaktis_list import viBakti, prAtipadika, encoding
from manual_list import test_list_slp1, test_list_devanagari

if __name__ == "__main__":
    import logging
    #logging.basicConfig(level=logging.INFO)
    enable_console_logger()
    enable_file_logger(level=logging.DEBUG)
    from sanskrit_parser.generator.sutras_yaml import sutra_list

    test_prakriya(sutra_list, test_list_slp1, test_list_devanagari)
    for v in viBakti:
        if v in encoding:
            check_vibhakti(
                generate_vibhakti(prAtipadika[v], viBakti[v], encoding[v]),
                sutra_list, encoding[v])
        else:
            check_vibhakti(generate_vibhakti(prAtipadika[v], viBakti[v]),
                           sutra_list)