Beispiel #1
0
    def algorithms(self):
        """Returns a list of stemming algorithms provided by the py-stemmer
        library.
        """

        import Stemmer  # @UnresolvedImport

        return Stemmer.algorithms()
    def algorithms(self):
        """Returns a list of stemming algorithms provided by the py-stemmer
        library.
        """

        import Stemmer  # @UnresolvedImport

        return Stemmer.algorithms()
Beispiel #3
0
    def add_subparser(cls, parser):
        subparser = parser.add_parser("set-stemmer",
                                      help="Configure a stemmer")

        subparser.set_defaults(run=cls.run)

        subparser.add_argument("language", choices=Stemmer.algorithms(),
                               help="Stemmer language")
Beispiel #4
0
    def add_subparser(cls, parser):
        subparser = parser.add_parser("set-stemmer",
                                      help="Configure a stemmer")

        subparser.set_defaults(run=cls.run)

        subparser.add_argument("language", choices=Stemmer.algorithms(),
                               help="Stemmer language")
 def _create_stemmers():
     """Create stemmers dictionary for all possible languages."""
     stemmers_initialized = {}
     for src_lang in Stemmer.algorithms():
         try:
             dst_lang = _lang_map.get(src_lang)
             if dst_lang:
                 stemmers_initialized[dst_lang] = Stemmer.Stemmer(src_lang, 40000)
         except (TypeError, KeyError):
             pass
     return stemmers_initialized
 def _create_stemmers():
     """Create stemmers dictionary for all possible languages."""
     stemmers_initialized = {}
     for src_lang in Stemmer.algorithms():
         try:
             dst_lang = _lang_map.get(src_lang)
             if dst_lang:
                 stemmers_initialized[dst_lang] = Stemmer.Stemmer(
                     src_lang, 40000)
         except (TypeError, KeyError):
             pass
     return stemmers_initialized
Beispiel #7
0
        help=("Only evaluate on the subset of unknown/out-of-vocabulary "
              "tokens; requires TRAINFILE"),
    )
    parser.add_argument(
        "--print",
        action="store_true",
        default=False,
        help=("Print the data that will be compared"),
    )
    if len(sys.argv) < 2:
        parser.print_help()
        exit(1)
    args = parser.parse_args()

    if args.only_knowns and args.only_unknowns:
        parser.error("can't select both --only-knowns and --only-unknowns")
    if (args.only_knowns or args.only_unknowns) and not args.trainfile:
        parser.error("--only-knowns/--only-unknowns requires TRAINFILE")
    stemmer = None
    if args.stem:
        import Stemmer

        try:
            stemmer = Stemmer.Stemmer(args.stem.lower())
        except KeyError:
            parser.error(
                "No stemming algorithm for '{}'; valid choices are: {}".format(
                    args.stem, ", ".join(Stemmer.algorithms())))

    main(args, stemmer=stemmer)
Beispiel #8
0
def run():
    parser = argparse.ArgumentParser(description="A chat bot")

    # database options
    db_parser = argparse.ArgumentParser(add_help=False)
    db_parser.add_argument(
        '--dbname', default='chains',
        help="Specifies the brain database.")

    # simulation options
    note = ("Note that this option is overridden by database settings and "
            "so is only used at database initialisation time.")
    modelling_parser = argparse.ArgumentParser(add_help=False)
    modelling_parser.add_argument(
        '--chain-order', type=int, default=DEF_CHAIN_ORDER,
        help="Set the simulation chain size parameter. " + note)
    modelling_parser.add_argument(
        '--language', choices=Stemmer.algorithms(), default='english',
        help="Set the simulation language for the stemmer. " + note)

    # learning options
    learning_parser = argparse.ArgumentParser(add_help=False)
    learning_parser.add_argument(
        'infile', metavar='INFILE', nargs='?', type=argparse.FileType('r'),
        default=sys.stdin,
        help="An input file from which to learn")

    # reply options
    reply_parser = argparse.ArgumentParser(add_help=False)
    reply_parser.add_argument(
        'message', metavar='MSG', nargs='+', action='append',
        help="Specify a message to respond to.")

    subparsers = parser.add_subparsers(title='Subcommands', dest='subcommand')
    subparsers.required = True

    ### learn command ###
    learn_subparser = subparsers.add_parser(
        'learn', help="add source data to the corpus",
        parents=[learning_parser, db_parser, modelling_parser])
    learn_subparser.set_defaults(func=do_learn)

    ### response command
    reply_subparser = subparsers.add_parser(
        'reply', help="send a message to get a reply back",
        parents=[reply_parser, db_parser, modelling_parser])
    reply_subparser.set_defaults(func=do_response)

    ### shell command
    shell_subparser = subparsers.add_parser(
        'shell', help="enter an interactive shell",
        parents=[db_parser, modelling_parser])
    shell_subparser.set_defaults(func=do_shell)

    dargs = vars(parser.parse_args())

    for option in ('file', 'message'):
        if dargs.get(option):
            dargs[option] = [x for xs in dargs[option] for x in xs]

    dargs['func'](dargs)