File size: 1,546 Bytes
e50fe35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
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
57
58
59
# 
#  Copyright (c) 2013-present, Anoop Kunchukuttan
#  All rights reserved.
#  
#  This source code is licensed under the MIT license found in the
#  LICENSE file in the root directory of this source tree.
# 

import os

"""
Path to the Indic NLP Resources directory
"""
INDIC_RESOURCES_PATH=''

def init():
    """
    Initialize the module. The following actions are performed:

    - Checks of INDIC_RESOURCES_PATH variable is set. If not, checks if it can beb initialized from 
        INDIC_RESOURCES_PATH environment variable. If that fails, an exception is raised
    """
    global INDIC_RESOURCES_PATH 
    try: 
        if INDIC_RESOURCES_PATH=='':
            INDIC_RESOURCES_PATH=os.environ['INDIC_RESOURCES_PATH']
    except Exception as e: 
        raise IndicNlpException('INDIC_RESOURCES_PATH not set')

    if INDIC_RESOURCES_PATH=='': 
        raise IndicNlpException('INDIC_RESOURCES_PATH not set')



def get_resources_path(): 
    """
        Get the path to the Indic NLP Resources directory
    """
    return INDIC_RESOURCES_PATH

def set_resources_path(resources_path): 
    """
        Set the path to the Indic NLP Resources directory
    """
    global INDIC_RESOURCES_PATH 
    INDIC_RESOURCES_PATH=resources_path

class IndicNlpException(Exception):
    """
        Exceptions thrown by Indic NLP Library components are instances of this class.  
        'msg' attribute contains exception details.
    """
    def __init__(self, msg):
        self.msg = msg 

    def __str__(self):
        return repr(self.msg)