vi3k6i5 / flashtext

Extract Keywords from sentence or Replace keywords in sentences.
MIT License
5.58k stars 598 forks source link

Added add_keywords_from_file_dict function #124

Open rudrashisgorai opened 3 years ago

rudrashisgorai commented 3 years ago

To add keywords from a file in the form key-value map. The idea was to read a list from the file in the form of key and value (in the form of list).

    Args:
        keyword_file : path to keywords file
        sep : unique separator for each line of the the keyword_file
        encoding : specify the encoding of the file

    Examples:
        keywords file format can be like: 
        Each line contains a new key value pair and has a single separator . 
        Separator should be unique in lines. 
        Value is in form of a list.
        Quotation marks only required for values in the value list.

        >>> # Option 1: config.txt content 
        >>> # key inv single = ['invoice'] 
        >>> # key_inv_number = ['invoice number', 'invoice no', 'invoice #', 'invoice#'] 
        >>> # key inv_date = ['invoice date', 'invoice dt', 'issue date', 'date of invoice', 'date of issue', 'issue dt', 'dt of issue'] 

        >>> keyword_processor.add_keywords_from_file_dict('config.txt' ,sep='=')

    Raises:
        IOError: If `keyword_file` path is not valid.
        AttributeError: No separator provided in the line. Value of key should be a list.
        AttributeError: Multiple separators present or choose a unique for the lines