# Match a two items from two different receipts

I have two different invoices or receipts. One is a Purchase order one is something like a receipt(acknowledgement).

Suppose I have ordered(PO) Wine:

1. White Wine
2. Red Wine
3. Rose Wine

And I receive the acknowledgement as:

1. Wine Red Jacobs Creek
2. White Wine
3. Winter's Hill Estate Dry Rose

I want to match the strings (items) in the Purchase Order and the Invoice.

Can you suggest me ways to do it.

I have tried vectorization using Count Vectorization Alg Then have used distance measures to calculate similarity using: 'dice', 'rogerstanimoto', 'yule', 'hamming', 'jaccard', 'braycurtis', 'canberra', 'cityblock', 'correlation', 'cosine', 'euclidean', and 'minkowski'

The problem is the position of Words.

Red Wine is will not be similar to Wine Red. But that should not be the case.

I have tried Word2Vec Algorithm too but as this is not language technically just Nouns. It did not work.

You can try some approximate string matching which gives a confidence score. For example, you can try out with Levenshtein distance, but adjusted with the length of the strings using a probabilistic model; or, you can try out with Jaccard similarity on 3-grams and special treatment on word boundaries, and then calibrated into probabilities. Now you have an n by n matrix of probabilities.

After this you need to perform a matching. The final likelihood is the product of each single probability. To maximize it, you can try to maximize the sum of logs of individual probabilities. Having taken logarithms of each probability, this now becomes an (additive) assignment problem which has implementations in R or Python.

If you are using Python try the fuzzywuzzy package:

FuzzyWuzzy

Fuzzy string matching like a boss. It uses Levenshtein Distance to calculate the differences between sequences in a simple-to-use package.

(Source)

Word Mover’s Distance (WMD) is an algorithm for finding the distance between phrases. WMD is based on word embeddings (e.g., word2vec) which encode the semantic meaning of words into dense vectors.

The WMD distance measures the dissimilarity between two text documents as the minimum amount of distance that the embedded words of one document need to "travel" to reach the embedded words of another document.

For example:

The gensim package has a WMD implementation.

For your problem, you would compare the Purchase Order items and the Invoice items. Find the items that have the lowest WMD.