Find out the same and different phrase word segmentation of a sentence (algorithm)

Source: Internet
Author: User
Find out the same and different Phrase Word Segmentation of two sentences (algorithm) statement 1 "CSDN Forum is a very good forum" statement 2 "CSDN is a good forum" the following result is: CSDN = & gt; 2 forum = & gt; 2 is a = & gt; 2 very = & gt; 1 good = & gt; 2 jar = & gt; 1, PHPcode $ a = 'csdn Forum is to find the same and different Phrase Word Segmentation for two sentences (algorithm ideas)
Statement 1 "CSDN Forum is a very good forum"
Statement 2 "CSDN is a good Jar"

Returns the following results after the same variance

CSDN => 2
Forum => 2
Yes => 2
Very => 1
Good => 2
Jar => 1

------ Solution --------------------
PHP code
$ A = 'csdn Forum is a very good BBS '; $ B = 'csdn is a good bucket'; print_r (Sunday ($ a, $ B )); function Sunday ($ a, $ B) {// Check the input string's character set mb_internal_encoding (mb_check_encoding ($ a, 'utf-8 ')? 'Utf-8': 'gbk'); // splits the input string into an array, mainly for the convenience of writing the following code $ t = array (); for ($ I = 0; $ I
  
   
= Count ($ a) break;} elseif ($ k) break;} // Check matching conditions if ($ n-$ I> 1) {if ($ buf) {$ r [] = $ buf; $ buf = '';} $ r [] = join ('', array_slice ($ a, $ I, $ n-$ I); $ I = $ n;} else $ buf. = $ a [$ I ++];} if ($ buf) $ r [] = $ buf; list ($ B, $ a) = array ($, $ B); // exchange two groups of data, and try again} while ($ loop --); return array_count_values ($ r );}
  

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.