Separation of Chinese word segmentation for search and collection of brand models such as mobile phones

Source: Internet
Author: User

A long time ago, I wrote a mobile phone search query, which involves the separation of mobile phone types and models.

Some people asked this question a long time ago, so I wrote a note to release the draft of this function, and wrote some of these instructions.

Function description, such as search input: Nokia N95, will be split into brand: Nokia model: N95

For mobile phone data collection, you can also use this function to separate the brand name and model.

SetSearchKey ("Nokia N95", out Nokia, out N95 );

 

The function code is as follows:

 

Protected void SetSearchKey (string keyword, out string goodsName, out string goodsModel)
{
Keyword = keyword. ToLower (). Trim ();
If (keyword. Contains ("") // with spaces, separate
{
GoodsName = keyword. Split ('') [0]. Trim ();
GoodsModel = keyword. Split ('') [1]. Trim ();
}
Else if (Regex. match (keyword, @ "^ [\ u4E00-\ u9FA5] + [\ w \ d] + "). success) // starts with a Chinese character, including English and separated
{
GoodsName = Regex. Match (keyword, @ "^ ([\ u4E00-\ u9FA5] +) [\ w \ d] +"). Groups [1]. Value;
GoodsModel = keyword. Replace (goodsName, string. Empty );
}
Else
{
String [] keys = new string [] {"nec", "lg", "vk", "cect "};
For (int I = 0; I <keys. Length; I ++)
{
If (keyword. IndexOf (keys [I]) = 0)
{
GoodsName = keys [I];
GoodsModel = keyword. Replace (goodsName, string. Empty );
Return;
}
}
GoodsName = keyword;
GoodsModel = keyword;

}
}

 

 

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.