o
    wi(                     @   s$   d dl m Z  d
ddZdddZd	S )    )arrayFc                 C   sT  |r	t | |ddS | |krdS t| t|}}|dkr&t|| |kr&dS |dkr,|S |dkr2|S ||k r@||}}|| } }tdt|d }td|d D ]I}||d< |d }td|d D ]*}	||	 }
t| |d  ||	d  k}t||	 d ||	d  d || ||	< |
}qa|dkrt||kr dS qP|dkr|| |krdS || S )a  Compute the absolute Levenshtein distance between the two sequences
	`seq1` and `seq2`.
	
	The Levenshtein distance is the minimum number of edit operations necessary
	for transforming one sequence into the other. The edit operations allowed are:
	
		* deletion:     ABC -> BC, AC, AB
		* insertion:    ABC -> ABCD, EABC, AEBC..
		* substitution: ABC -> ABE, ADC, FBC..
	
	The `max_dist` parameter controls at which moment we should stop computing the
	distance between the provided sequences. If it is a negative integer, the
	distance will be computed until the sequences are exhausted; otherwise, the
	computation will stop at the moment the calculated distance is higher than
	`max_dist`, and then return -1. For example:
	
		>>> levenshtein("abc", "abcd", max_dist=1)  # dist = 1
		1
		>>> levenshtein("abc", "abcde", max_dist=1) # dist = 2
		-1
	
	This can be a time saver if you're not interested in the exact distance, but
	only need to check if the distance between the given sequences is below a
	given threshold.
	
	The `normalized` parameter is here for backward compatibility; providing
	it will result in a call to `nlevenshtein`, which should be used directly
	instead. 
	   )methodr   r   L)nlevenshteinlenabsr   rangeintmin)seq1seq2max_dist
normalizedlen1len2columnxlastyoldcost r   R/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/distance/_levenshtein.pylevenshtein   s:   

(r   r   c                 C   s  | |krdS t | t |}}|dks|dkrdS ||k r'||}}|| } }|dkr4t| |t| S |dkr<tdtdt|d }tdt|d }td|d D ]|}| |d< |d< |d  }}	td|d D ]d}
||
 }||
d  d }||
 d }|| |d  ||
d  k }t|||||
< |}||
 }|||
 kr||
d  d nd}|||
 kr||
 d nd}|||
 kr|	d nd}t|||||
< |}	qlqU||
 t||
  S )a  Compute the normalized Levenshtein distance between `seq1` and `seq2`.
	
	Two normalization methods are provided. For both of them, the normalized
	distance will be a float between 0 and 1, where 0 means equal and 1
	completely different. The computation obeys the following patterns:
	
		0.0                       if seq1 == seq2
		1.0                       if len(seq1) == 0 or len(seq2) == 0
		edit distance / factor    otherwise
	
	The `method` parameter specifies which normalization factor should be used.
	It can have the value 1 or 2, which correspond to the following:
	
		1: the length of the shortest alignment between the sequences
		   (that is, the length of the longest sequence)
		2: the length of the longest alignment between the sequences
	
	Which normalization factor should be chosen is a matter of taste. The first
	one is cheap to compute. The second one is more costly, but it accounts
	better than the first one for parallelisms of symbols between the sequences.
		
	For the rationale behind the use of the second method, see:
	Heeringa, "Measuring Dialect Pronunciation Differences using Levenshtein
	Distance", 2004, p. 130 sq, which is available online at:
	http://www.let.rug.nl/~heeringa/dialectology/thesis/thesis.pdf
	g        r   g      ?r      z-expected either 1 or 2 for `method` parameterr   )r   r   float
ValueErrorr   r
   r   max)r   r   r   r   r   r   lengthr   r   llastr   r   icdcrcloldlicldclrcr   r   r   r   H   s@   

 r   N)r   F)r   )r   r   r   r   r   r   r   <module>   s   
B