コード例 #1
0
ファイル: app.py プロジェクト: rutulgandhi05/examples
def main(task, num_docs, top_k):
    workspace_path = '/tmp/jina/urbandict'
    os.environ['TMP_WORKSPACE'] = get_random_ws(workspace_path)
    print(f'{os.environ["TMP_WORKSPACE"]}')
    data_fn = os.environ.get('WASHED_DATA_DIR', os.path.join(workspace_path, 'urbandict-word-defs.csv'))
    if task == 'index':
        f = Flow().load_config('flow-index.yml')
        with f:
            f.index_lines(filepath=data_fn, size=num_docs, batch_size=16)
    elif task == 'query':
        f = Flow().load_config('flow-query.yml')
        with f:
            while True:
                text = input('word definition: ')
                if not text:
                    break
                ppr = lambda x: print_topk(x, text)
                f.search_lines(lines=[text, ], output_fn=ppr, topk=top_k)
    elif task == 'query_restful':
        f = Flow().load_config('flow-query.yml')
        f.use_rest_gateway()
        with f:
            f.block()
    else:
        raise NotImplementedError(
            f'unknown task: {task}. A valid task is `index` or `query` or `query_restful`.')
コード例 #2
0
ファイル: app.py プロジェクト: smartadpole/examples
def query(num_docs, top_k):
    config(num_docs, mode = 'search')
    f = Flow().load_config('flow-query.yml')
    with f:
        while True:
            text = input('please type a sentence: ')
            if not text:
                break
            ppr = lambda x: print_topk(x, text)
            f.search_lines(lines=[text, ], output_fn=ppr, top_k=top_k)
コード例 #3
0
ファイル: app.py プロジェクト: cristianmtr/examples
def query(top_k):
    f = Flow().load_config("flow-query.yml")
    with f:
        while True:
            text = input("please type a description: ")
            if not text:
                break

            def ppr(x):
                print_topk(x, text)
            f.search_lines(lines=[text, ], output_fn=ppr, top_k=top_k)
コード例 #4
0
ファイル: app.py プロジェクト: carlosb1/examples-python
def query(num_docs, top_k):
    f = Flow().load_config('flow-query.yml')
    with f:
        while True:
            text = input('please type a sentence: ')
            if not text:
                break

            def ppr(x):
                return print_topk(x, text)
            f.search_lines(lines=[text, ], output_fn=ppr, top_k=top_k)
コード例 #5
0
ファイル: app.py プロジェクト: snayan06/examples
def query(top_k):
    f = Flow().load_config("flows/query.yml")
    with f:
        while True:
            text = input("please type a sentence: ")
            if not text:
                break

            def ppr(x):
                print_topk(x, text)

            f.search_lines(lines=[text, ], line_format='text', on_done=ppr, top_k=top_k)
コード例 #6
0
def query(top_k):
    f = Flow().load_config("flows/query.yml")
    with f:
        while True:
            text = input("please type a sentence: ")
            if not text:
                break

            with TimeContext(f'QPS: query with 1', logger=f.logger):
                f.search_lines(lines=[
                    text,
                ], line_format='text', top_k=top_k)
コード例 #7
0
ファイル: app.py プロジェクト: rutulgandhi05/examples
def main(task, num_docs, top_k):
    os.environ['TMP_WORKSPACE'] = get_random_ws(os.environ['TMP_DATA_DIR'])
    data_path = os.path.join(os.environ['TMP_DATA_DIR'], 'character-lines.csv')
    if task == 'index':
        f = Flow().load_config('flow-index.yml')
        with f:
            f.index_lines(filepath=data_path, size=num_docs, batch_size=8)
    elif task == 'query':
        f = Flow().load_config('flow-query.yml')
        with f:
            while True:
                text = input('please type a sentence: ')
                if not text:
                    break
                ppr = lambda x: print_topk(x, text)
                f.search_lines(lines=[
                    text,
                ], output_fn=ppr, topk=top_k)
    else:
        raise NotImplementedError(
            f'unknown task: {task}. A valid task is either `index` or `query`.'
        )
コード例 #8
0
ファイル: app.py プロジェクト: saman-moeinsadat/examples
def main(task, num_docs, top_k):
    workspace_path = '/tmp/jina/urbandict'
    os.environ['WORKDIR'] = get_random_ws(workspace_path)
    data_fn = os.environ.get(
        'WASHED_DATA_DIR',
        os.path.join(workspace_path, 'urbandict-word-defs.csv'))
    if task == 'index':
        workspace = os.environ['WORKDIR']
        if os.path.exists(workspace):
            print(
                f'\n +---------------------------------------------------------------------------------+ \
                    \n |                                   🤖🤖🤖                                        | \
                    \n | The directory {workspace} already exists. Please remove it before indexing again. | \
                    \n |                                   🤖🤖🤖                                        | \
                    \n +---------------------------------------------------------------------------------+'
            )
        f = Flow().load_config('flow-index.yml')
        with f:
            f.index_lines(filepath=data_fn, size=num_docs, batch_size=16)
    elif task == 'query':
        f = Flow().load_config('flow-query.yml')
        with f:
            while True:
                text = input('word definition: ')
                if not text:
                    break
                ppr = lambda x: print_topk(x, text)
                f.search_lines(lines=[
                    text,
                ], output_fn=ppr, top_k=top_k)
    elif task == 'query_restful':
        f = Flow().load_config('flow-query.yml')
        f.use_rest_gateway()
        with f:
            f.block()
    else:
        raise NotImplementedError(
            f'unknown task: {task}. A valid task is `index` or `query` or `query_restful`.'
        )