Skip to main content

The library provides functions for fuzzy string matching, fuzzy round-off for floats and a fuzzy function of dividing a integer into a integer distribution according to given percentage.

Project description

Fuzzy Logic

The library provides functions for fuzzy string matching, fuzzy round-off of floats and a fuzzy function for dividing an integer into an integer distribution according to given percentage.

Requirements

  • Python 3.5 or higher

  • difflib

  • numpy

Installation

Using PIP via PyPI

pip install fuzzy_logic

Using PIP via Github

pip install git+git://github.com/shubhankar-mohan/fuzzy_logic.git

Manually via GIT

git clone git://github.com/shubhankar-mohan/fuzzy_logic.git
cd fuzzy_logic
python setup.py install

Examples

Fuzzy Numeric Functions

  • Fuzzy Round - Performs a Rounding off an an float to an integer, based on decimal part.
Args:
    x: float value which needs to be rounded
    break_point: (Default: 0.5) threshold for deciding if ceil or floor needs to be returned

Returns: ceil(x) if x-int(x) >= break_point else floor(x)
>>> from fuzzy_logic import fuzzynumeric
>>> fuzzynumeric.fuzzy_round(1.6)
>>> 2
>>> fuzzynumeric.fuzzy_round(1.6, break_point=0.8)
>>> 1
  • Fuzzy Distribution - The function divides a given integer into different percentages which are integer.

    Args:
        x: Integer which needs to be divided
        multiplier: Percentages in which integer needs to be divided
        round_type: (Default: fuzzy) ['floor', 'ceil', 'fuzzy'], Primary Round Type to be used while getting
                    base distribution.
        break_point: (Default: 0.8) It is needed if round_type is fuzzy. See fuzzy_round for details.
        guider_type: (Default: multiplier) ['multiplier', 'deficit_decimal', 'guider'] It defines how the left out
                      value after Primary Round off needs to be distributed. Multiplier used multiplier argument to
                      distribute, giving preference to highest. deficit_decimal uses decimal_part left after floor,
                      giving preference to highest. guider uses a given distribution for the same.
        guider: Needs is guider_type is guider. It is used to give preference to allocate left out
                      value after Primary Round off.
    
    Returns: A list of integer values, which are closest representation of percentage distribution of x according
            to multiplier.
    
    >>> from fuzzy_logic import fuzzynumeric
    >>> fuzzynumeric.fuzzy_integer_distribution(5, [.2, .3, .5])
    >>> [1, 1, 3]
    
    >>> fuzzynumeric.fuzzy_integer_distribution(5, [.2, .3, .5], round_type='ceil')
    >>> [1, 2, 2]
    >>> fuzzynumeric.fuzzy_integer_distribution(5, [.2, .3, .5], round_type='floor')
    >>> [1, 1, 3]
    >>> fuzzynumeric.fuzzy_integer_distribution(5, [.2, .3, .5], round_type='fuzzy', break_point=0.3)
    >>> [1, 2, 2]
    
    
    >>> fuzzynumeric.fuzzy_integer_distribution(5, [.2, .3, .5], guider_type='deficit_decimal')
    >>> [1, 1, 3]
    >>> fuzzynumeric.fuzzy_integer_distribution(5, [.333, .333, .333], guider_type='deficit_decimal')
    >>> [1, 2, 2]
    >>> fuzzynumeric.fuzzy_integer_distribution(7, [.2, .3, .5], guider_type='deficit_decimal')
    >>> [1, 2, 4]
    >>> fuzzynumeric.fuzzy_integer_distribution(7, [.2, .3, .5])
    >>> [1, 2, 4]
    
    >>> fuzzynumeric.fuzzy_integer_distribution(7, [.2, .3, .5], round_type='floor', guider_type='deficit_decimal')
    >>> [1, 2, 4]
    >>> fuzzynumeric.fuzzy_integer_distribution(8, [.2, .3, .5], round_type='floor', guider_type='deficit_decimal')
    >>> [2, 2, 4]
    >>> fuzzynumeric.fuzzy_integer_distribution(8, [.2, .3, .5], round_type='floor')
    >>> [1, 2, 5]
    >>> fuzzynumeric.fuzzy_integer_distribution(8, [.2, .3, .5], round_type='floor', guider=[1, 5, 2])
    >>> [1, 3, 4]
    

Fuzzy String Functions

  • String Similarity - Calculates Similarity between two strings.

    Args:
        string1: string 1
        string2: string 2
        method: (Default: 0) [0, 1] 0 is for Cosine Distance and 1 is for Levenshtein Distance
                rearrange_allowed: [True, False] Is rearrange allowed while calculating similarity. If set to true, sequence
                of words will be ignored while calculating similarity.
        drop_duplicates: [True, False] Weather to drop duplicates from a sentence. If set to true, all duplicates will
                be removed.
        clean_string: [True, False] If set to true, remove all non alpha-numeric characters including whitespaces
                and make all characters to lower case.
        filter_ascii: [True, False] If set to true, all characters other than ASCII will be removed.
    
    Returns: A float, representing similarity between string1 and string2.
    
    >>> from fuzzy_logic import fuzzystring
    
    >>> fuzzystring.string_similarity("mouse keyboard are part of computer", "mouse keyboard are part of computer", method=0)
    >>> 100.0
    >>> fuzzystring.string_similarity("mouse keyboard are part of computer", "mouse keyboard are part of computer.", method=0)
    >>> 100.0
    >>> fuzzystring.string_similarity("mouse keyboard are part of computer", "mouse keyboard are part of the computer", method=0)
    >>> 92.58
    
    >>> fuzzystring.string_similarity("mouse keyboard are part of computer", "mouse keyboard are part of computer", method=1)
    >>> 100.0
    >>> fuzzystring.string_similarity("mouse keyboard are part of computer", "mouse keyboard are part of computer.", method=1)
    >>> 98.59
    >>> fuzzystring.string_similarity("mouse keyboard are part of computer", "mouse keyboard are part of the computer", method=1)
    >>> 94.59
    
    
    >>> fuzzystring.string_similarity("mouse keyboard are part of computer", "keyboard mouse are part of computer", method=1)
    >>> 82.86
    >>> fuzzystring.string_similarity("mouse keyboard are part of computer", "keyboard mouse are part of computer", method=1, rearrange_allowed=True)
    >>> 100.0
    
    
    >>> fuzzystring.string_similarity("mouse mouse keyboard are part of computer", "mouse keyboard are part of computer", method=1)
    >>> 92.11
    >>> fuzzystring.string_similarity("mouse mouse keyboard are part of computer", "mouse keyboard are part of computer", method=1, drop_duplicates=True)
    >>> 100.0
    
  • Sub String Similarity - Returns maximum similarity between all possible sub-strings combinations of two strings based on levenshtein similarity.

    Args:
        string1: string 1
        string2: string 2
        clean_string: [True, False] If set to true, remove all non alpha-numeric characters including whitespaces
        			and make all characters to lower case.
        filter_ascii: [True, False] If set to true, all characters other than ASCII will be removed.
    
    Returns: A float, representing similarity between string1 and string2.
    
    >>> from fuzzy_logic import fuzzystring
    
    >>> fuzzystring.string_similarity("mouse mouse keyboard are part of computer", "mouse keyboard are part of computer")
    >>> 95.26
    >>> fuzzystring.substring_similarity("mouse mouse keyboard are part of computer", "mouse keyboard are part of computer")
    >>> 100.0
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fuzzy_logics-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fuzzy_logics-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file fuzzy_logics-0.1.1.tar.gz.

File metadata

  • Download URL: fuzzy_logics-0.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.0

File hashes

Hashes for fuzzy_logics-0.1.1.tar.gz
Algorithm Hash digest
SHA256 322d237fb4775636f45cc7ba5ea1387fdffa3d423b061058f87ff76096ba20b1
MD5 a4f647116fde211f8d313e56dfd8cd15
BLAKE2b-256 697081125dbbe055728ed95b5afd4d87d6cb72230309809c3e1f8a54c8c44621

See more details on using hashes here.

File details

Details for the file fuzzy_logics-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fuzzy_logics-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.0

File hashes

Hashes for fuzzy_logics-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 19a2ec9d1bec7952e6cd33e3135037d93aa288e99249251ef75bf0271ee5fcda
MD5 dfe5926172bb580b3ffc0c65ea3c849b
BLAKE2b-256 44896ddf930677675703a351b33bc6735cb97030b0068d3709154ec8a3f32d57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page