Issues (76)

crf_pos/api.py (12 issues)

1
"""
2
API
3
4
....................................................................................................
5
MIT License
6
7
Copyright (c) 2021-2023 AUT Iran, Mohammad H Forouhesh
8
Copyright (c) 2021-2022 MetoData.ai, Mohammad H Forouhesh
9
....................................................................................................
10
This module contains tools to download resources over http connections.
11
supported http links are:
12
    - https://github.com/MohammadForouhesh/crf-pos-persian/releases/download/v2.0.0.alpha/UPC_full_model_wapiti
0 ignored issues
show
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
13
    - https://github.com/MohammadForouhesh/crf-pos-persian/releases/download/v2.0.0.alpha/perpos.model
0 ignored issues
show
This line is too long as per the coding-style (102/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
14
    - https://raw.githubusercontent.com/MohammadForouhesh/crf-pos-persian/main/resources/corrections.txt
0 ignored issues
show
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
15
"""
16
17 1
import os
18 1
from typing import Union
19
20 1
import requests
21
22 1
http_dict = {'UPC_full_model_wapiti': 'https://github.com/MohammadForouhesh/crf-pos-persian/releases/download/v.2.2.2/UPC_full_model_wapiti',
0 ignored issues
show
This line is too long as per the coding-style (141/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
23
             'perpos.model': 'https://github.com/MohammadForouhesh/crf-pos-persian/releases/download/v.2.2.2/perpos.model',
0 ignored issues
show
This line is too long as per the coding-style (123/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
24
             'corrections.txt': 'https://raw.githubusercontent.com/MohammadForouhesh/crf-pos-persian/main/resources/corrections.txt'}
0 ignored issues
show
This line is too long as per the coding-style (133/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
25
26
27 1
def downloader(path: str, save_path: str, mode: str) -> Union[int, None]:
0 ignored issues
show
Either all return statements in a function should return an expression, or none of them should.
Loading history...
28
    """
29
    A tool to download and save files over https.
30
    supported http links are:
31
    - https://github.com/MohammadForouhesh/crf-pos-persian/releases/download/v2.0.0.alpha/UPC_full_model_wapiti
0 ignored issues
show
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
32
    - https://github.com/MohammadForouhesh/crf-pos-persian/releases/download/v.2.2.2/perpos.model
33
    - https://raw.githubusercontent.com/MohammadForouhesh/crf-pos-persian/main/resources/corrections.txt
0 ignored issues
show
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
34
35
    :param path:        The path to the desired file.
36
    :param save_path:   The intended storage path.
37
    :param mode:        The mode that it should be stored.
38
    :return:            If the file exists, it returns 0 (int), otherwise nothing would be returned.
39
    """
40 1
    if os.path.isfile(save_path): return 0
0 ignored issues
show
More than one statement on a single line
Loading history...
41 1
    try:
42 1
        print('Downloading resources ...')
43 1
        model_bin = requests.get(path, allow_redirects=True)
44 1
        with open(save_path, mode) as resource:
45 1
            resource.write(model_bin.content)
46
    except Exception as e:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "e" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
47
        raise e.with_traceback
0 ignored issues
show
Raising with_traceback while only classes or instances are allowed
Loading history...
48
49
50 1
def get_resources(dir_path: str, resource_name: str) -> str:
51
    """
52
    A tool to download required resources over internet.
53
    :param dir_path:        Path to the https link of the resource
54
    :param resource_name:   Resource name.
55
    :return:                Path to the downloaded resource.
56
    """
57 1
    save_dir = dir_path + 'resources/'
58 1
    os.makedirs(save_dir, exist_ok=True)
59 1
    downloader(path=http_dict[resource_name], save_path=save_dir + resource_name, mode='wb')
60
    return str(save_dir + resource_name)
61