def main(): args = docopt(__doc__, version='Addok 0.1') if args['--config']: os.environ['ADDOK_CONFIG_MODULE'] = args['--config'] from addok import config from addok.debug import Cli from addok.server import app from addok import batch from addok.index_utils import create_edge_ngrams # Hook for plugins to register themselves. if hasattr(config, 'ON_LOAD'): config.ON_LOAD() if args['serve']: from werkzeug.serving import run_simple run_simple(args['--host'], int(args['--port']), app, use_debugger=True, use_reloader=True) elif args['shell']: cli = Cli() cli() elif args['batch']: if args['<filepath>']: for path in args['<filepath>']: batch.process_file(path) elif not sys.stdin.isatty(): # Any better way to check for stdin? batch.process_stdin(sys.stdin) else: if args['--dbname']: config.PSQL['dbname'] = args['--dbname'] if args['--dbuser']: config.PSQL['user'] = args['--dbuser'] if args['--dbhost']: config.PSQL['host'] = args['--dbhost'] if args['--dbport']: config.PSQL['port'] = args['--dbport'] if args['--limit']: config.PSQL_LIMIT = args['--limit'] batch.process_psql() elif args['ngrams']: create_edge_ngrams()
def test_create_edge_ngrams(config): config.MIN_EDGE_NGRAMS = 2 doc = { 'id': 'xxxx', 'lat': '49.32545', 'lon': '4.2565', 'name': '28 Lilas', # 28 should not appear in ngrams 'city': 'Paris' } index_document(doc, update_ngrams=False) assert not DB.exists('n|li') assert not DB.exists('n|lil') assert not DB.exists('n|pa') assert not DB.exists('n|par') create_edge_ngrams() assert DB.exists('n|li') assert DB.exists('n|lil') assert DB.exists('n|pa') assert DB.exists('n|par') assert not DB.exists('n|28') assert len(DB.keys()) == 12