Skip to content

bold_cli

BoldCli

Source code in datasets/services/bold_cli.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class BoldCli:
    @staticmethod
    def cmd(command: List[str], **kwargs) -> Iterator[str]:
        yield from execute_command(
            [str(BIN_DIR / 'bold-cli'), *command],
            cwd=STORAGE_DIR,
            **kwargs
        )

    @staticmethod
    def search(
        index_path: Path,
        query: str, limit: int, offset: int,
        pos: int = None, url: int = None,
        min_count: int = None, max_count: int = None,
        **kwargs
    ) -> dict:
        filter_args = []
        if pos is not None:
            filter_args.append(f'--pos={pos}')
        if url is not None:
            filter_args.append(f'--url={url}')
        if min_count is not None:
            filter_args.append(f'--min-count={min_count}')
        if max_count is not None:
            filter_args.append(f'--max-count={max_count}')

        print([
            'search',
            '--index', str(index_path),
            '--limit', str(limit),
            '--offset', str(offset),
            *filter_args,
            query
        ])

        result_lines = list(BoldCli.cmd([
            'search',
            '--index', str(index_path),
            '--limit', str(limit),
            '--offset', str(offset),
            *filter_args,
            query
        ], ignore_errors=True, **kwargs))

        # print(''.join(result_lines))
        return json.loads(''.join(result_lines))

cmd(command, **kwargs) staticmethod

Source code in datasets/services/bold_cli.py
11
12
13
14
15
16
17
@staticmethod
def cmd(command: List[str], **kwargs) -> Iterator[str]:
    yield from execute_command(
        [str(BIN_DIR / 'bold-cli'), *command],
        cwd=STORAGE_DIR,
        **kwargs
    )

search(index_path, query, limit, offset, pos=None, url=None, min_count=None, max_count=None, **kwargs) staticmethod

Source code in datasets/services/bold_cli.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@staticmethod
def search(
    index_path: Path,
    query: str, limit: int, offset: int,
    pos: int = None, url: int = None,
    min_count: int = None, max_count: int = None,
    **kwargs
) -> dict:
    filter_args = []
    if pos is not None:
        filter_args.append(f'--pos={pos}')
    if url is not None:
        filter_args.append(f'--url={url}')
    if min_count is not None:
        filter_args.append(f'--min-count={min_count}')
    if max_count is not None:
        filter_args.append(f'--max-count={max_count}')

    print([
        'search',
        '--index', str(index_path),
        '--limit', str(limit),
        '--offset', str(offset),
        *filter_args,
        query
    ])

    result_lines = list(BoldCli.cmd([
        'search',
        '--index', str(index_path),
        '--limit', str(limit),
        '--offset', str(offset),
        *filter_args,
        query
    ], ignore_errors=True, **kwargs))

    # print(''.join(result_lines))
    return json.loads(''.join(result_lines))