PHP Similarity algorithm

Source: Internet
Author: User

Wrote for a long time forgot to save, embarrassed, first put here

Catalogue

1. tf-IDF2. Cosine algorithm based on space vector 3. Longest common sub-sequence 4. Minimum editing distance algorithm  5. Similar_text

1. TF-IDF

Relevant Link:

http://qianxunniao.iteye.com/blog/1831780

2. Cosine algorithm based on space vector

After the word frequency as a vector component, each file is converted into a vector, by calculating the cosine between the vectors, essentially calculating the similarity of the frequency of different texts.

3. Longest common sub-sequence
The biggest drawback of this algorithm is that CPU consumption is computationally large

1 . Two strings are composed of rows and columns in a matrix 2 . Calculates whether the row and column characters are the same for each node, or 1 if the same.  3

To further enhance the algorithm, we can add the value of the same node to the upper left corner (D[i-1,j-1]) to get the maximum length of the common substring. As a result, you can intercept the maximum substring simply by the line number and the maximum value.

Relevant Link:

HTTPS://segmentfault.com/q/1010000000738974http://www.speedphp.com/ thread-4840-1-1.htmlhttp://www.cnblogs.com/liangxiaxu/archive/2012/05/05/2484972.html 

4. Minimum editing distance algorithm

Set A, B is two strings, the narrow editing distance is defined as the minimum required to convert a to B (delete a character in a), insert (insert a character in a) and replace (a character in a to replace the other character) the number of times, with an Ed (A, B) to represent. Intuitively, the more steps required to convert two strings to each other, the greater the difference

1. Process the two-part text and replace all non-text characters with the fragment marker "#"2. Longer text as the base text, traversing the short text after the fragment, found that the long texts contain the short sentence after the length of the article removed, did not find the matching words cumulative length 3. Compare the length of the remaining text with the length of the two paragraphs and its ratio to the mismatch ratio

The Levenshtein () function in PHP has already implemented this function

Relevant Link:

http://php.net/manual/zh/function.levenshtein.php

5. Similar_text

Relevant Link:

http://php.net/manual/zh/function.metaphone.phphttp://php.net/manual/zh/ function.soundex.phphttp://

Copyright (c) Littlehann All rights reserved

PHP Similarity algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.