Esempio n. 1
0
def cli(ctx, debug, corrector_index, corrector):
    ctx.obj['corrector'] = TYPO_CLASSES.get(corrector)
    ctx.obj['corrector_index'] = corrector_index
    ctx.obj['debug'] = debug
    logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
Esempio n. 2
0
File: wsgi.py Progetto: kalloc/typod
                if i > limit:
                    break
                results.append(u"".join(word for word, weight in p))
            result = '\n'.join(results).encode('utf-8')
        return [result]

    return application


@click.command()
@click.option('--index',
              type=click.Path(readable=True, resolve_path=True),
              default="index.data",
              required=True)
@click.option('--corrector',
              type=click.Choice(TYPO_CLASSES.keys()),
              default='default')
@click.option('--format', type=click.Choice(['text', 'json']), default='text')
@click.option('--lang', type=click.Choice(['ru', 'en', 'other']), default='ru')
@click.option('--max-candidates', type=click.INT, default=1)
@click.option('--limit', type=click.INT, default=10)
def cli(*a, **kw):
    pass


ctx = cli.make_context('wsgi', sys.argv[1:])
corrector_cls = TYPO_CLASSES.get(ctx.params['corrector'])
corrector_inst = corrector_cls(ctx.params['index'],
                               max_candidates=ctx.params['max_candidates'],
                               lang=ctx.params['lang'])
application = make_app(corrector_inst, ctx.params['format'],
Esempio n. 3
0
import click

from correctors import TYPO_CLASSES
from cmd_console import console_group
from cmd_server import server_group
from cmd_convert import convert_group

logger = logging.getLogger(__name__)


@click.command(cls=click.CommandCollection,
               sources=[server_group, convert_group, console_group])
@click.option('--debug', is_flag=True, default=False)
@click.option('--corrector-index',
              type=click.Path(readable=True, resolve_path=True),
              default="index.data",
              required=True)
@click.option('--corrector',
              type=click.Choice(TYPO_CLASSES.keys()),
              default='default')
@click.pass_context
def cli(ctx, debug, corrector_index, corrector):
    ctx.obj['corrector'] = TYPO_CLASSES.get(corrector)
    ctx.obj['corrector_index'] = corrector_index
    ctx.obj['debug'] = debug
    logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)


if __name__ == '__main__':
    cli(obj={})
Esempio n. 4
0
                typo = qs.get('query', [''])[0]
            elif method == 'POST':
                typo = env['wsgi.input'].read()
            else:
                start_response('405 Method Not Allowed')
                return []
            start_response('200 OK',
                           [('Content-Type', 'text/plain; charset=UTF-8')])
            typo = typo.decode('utf-8').strip()
            corrected, _ = corrector.suggestion(typo)
            result = corrected.encode('utf-8')
            return [result]
    return application


@click.command()
@click.option('--index',
              type=click.Path(writable=True, resolve_path=True),
              default="index.data", required=True)
@click.option('--corrector', type=click.Choice(TYPO_CLASSES.keys()),
              default='default')
def cli(*a, **kw):
    pass


ctx = cli.make_context('wsgi', sys.argv[1:])
corrector_inst = TYPO_CLASSES.get(ctx.params['corrector'])(ctx.params['index'])
application = make_app(corrector_inst)

__all__ = ['application']
Esempio n. 5
0
def cli(ctx, debug, corrector_index, corrector):
    ctx.obj['corrector'] = TYPO_CLASSES.get(corrector)
    ctx.obj['corrector_index'] = corrector_index
    ctx.obj['debug'] = debug
    logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
Esempio n. 6
0
import logging

import click

from correctors import TYPO_CLASSES
from cmd_console import console_group
from cmd_server import server_group
from cmd_convert import convert_group

logger = logging.getLogger(__name__)


@click.command(cls=click.CommandCollection,
               sources=[server_group, convert_group, console_group])
@click.option('--debug', is_flag=True, default=False)
@click.option('--corrector-index',
              type=click.Path(readable=True, resolve_path=True),
              default="index.data",
              required=True)
@click.option('--corrector', type=click.Choice(TYPO_CLASSES.keys()),
              default='default')
@click.pass_context
def cli(ctx, debug, corrector_index, corrector):
    ctx.obj['corrector'] = TYPO_CLASSES.get(corrector)
    ctx.obj['corrector_index'] = corrector_index
    ctx.obj['debug'] = debug
    logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)

if __name__ == '__main__':
    cli(obj={})
Esempio n. 7
0
            result = json.dumps(suggestions, ensure_ascii=False).encode("utf-8")
        else:
            results = []
            for i, p in enumerate(product(*suggestions)):
                if i > limit:
                    break
                results.append(u"".join(word for word, weight in p))
            result = "\n".join(results).encode("utf-8")
        return [result]

    return application


@click.command()
@click.option("--index", type=click.Path(readable=True, resolve_path=True), default="index.data", required=True)
@click.option("--corrector", type=click.Choice(TYPO_CLASSES.keys()), default="default")
@click.option("--format", type=click.Choice(["text", "json"]), default="text")
@click.option("--lang", type=click.Choice(["ru", "en", "other"]), default="ru")
@click.option("--max-candidates", type=click.INT, default=1)
@click.option("--limit", type=click.INT, default=10)
def cli(*a, **kw):
    pass


ctx = cli.make_context("wsgi", sys.argv[1:])
corrector_cls = TYPO_CLASSES.get(ctx.params["corrector"])
corrector_inst = corrector_cls(
    ctx.params["index"], max_candidates=ctx.params["max_candidates"], lang=ctx.params["lang"]
)
application = make_app(corrector_inst, ctx.params["format"], ctx.params["limit"])