# Path: search/utils.py
# def _dec(fl):
# def normalize(iterable):
# def scale_to_one(iterable):
# def weighted_average(values, weights):
# def tokenize(string):
# def max_distance(phrase, word_index):
# def position_similarity(token1, token2, phrase1, phrase2):
# 
# Path: search/config.py
# MATCH_WEIGHT = 0.2
# DIST_WEIGHT = 0.8
# THRESHOLD = 0.75
# MIN_WORD_LENGTH = 3
# STR_SPLIT_REGEX = r'\W+'


import jellyfish as jf
from search import utils, config
"""
Search API core module

Contains the main functions to get match values and searching
"""



def similarity(query, string):
    """
    Calculate the match for the given `query` and `string`.

    The match is calculated using the `jaro winkler` for each set of the matrix
    (`query` x `string`) and takes into consideration the position difference
    into the strings.

    Arguments:
        query (str): search query
        string (str): string to test against

    Returns:
        float: normalized value indicating the probability of match, where
        0 means completely dissimilar and 1 means equal.
    """

    # split the two strings cleaning out some stuff
    query = utils.tokenize(query.lower())

# Path: search/utils.py
# def _dec(fl):
# def normalize(iterable):
# def scale_to_one(iterable):
# def weighted_average(values, weights):
# def tokenize(string):
# def max_distance(phrase, word_index):
# def position_similarity(token1, token2, phrase1, phrase2):
# 
# Path: search/config.py
# MATCH_WEIGHT = 0.2
# DIST_WEIGHT = 0.8
# THRESHOLD = 0.75
# MIN_WORD_LENGTH = 3
# STR_SPLIT_REGEX = r'\W+'


# Path: search/core.py
import jellyfish as jf
from search import utils, config

"""
Search API core module

Contains the main functions to get match values and searching
"""



def similarity(query, string):
    """
    Calculate the match for the given `query` and `string`.

    The match is calculated using the `jaro winkler` for each set of the matrix
    (`query` x `string`) and takes into consideration the position difference
    into the strings.

    Arguments:
        query (str): search query
        string (str): string to test against

    Returns:
        float: normalized value indicating the probability of match, where
        0 means completely dissimilar and 1 means equal.
    """

    # split the two strings cleaning out some stuff
    query = utils.tokenize(query.lower())

    string = utils.tokenize(string.lower())