C # Regular Expression for sentence segmentation, correct sentence Segmentation

Source: Internet
Author: User

Due to the need, I wrote a regular expression for sentence segmentation and considered various special cases.

Public static RegEx uselesspunctionregex = new RegEx (@"'(?! (S | T | re | M) (| $) | \. $ | \. | \. {2,} | '| ~ |! | @ | # | \ $ | % | \ ^ | \ * | \ (| \) | (^ | [^ \ W]) -+ |-+ ($ | [^ \ W]) | _ | = | \ + | \ [| \] |\{|\}|<|>|\||||// |;|: | "" | • |-|, | \? | × |! | · |... |-| (|) |, |: | '| "|, |. |? ");

For example, the following sentence can be correctly divided:

@ "What's your name? My name is Han Mei-mei. I am from U. S.! Nice to meet you! "

It is divided:

What's your name

My name is Han Mei-mei

I am from U. S.

Nice to meet you

It ensures that the special punctuation marks do not become delimiters, such as what's, Mei-mei, U. S..

I pressed all the punctuation on the keyboard.

Note: This regular expression cannot recognize the period separator without spaces. For example

Nice to meet you. Nice to meet you, too.

Can only be divided

Nice to meet you. Nice to meet you

Too

To solve this problem, we recommend that you first use the opennlp tool, which contains a class named

Englishmaximumentropysentencedetector

It has a method named

Sentencedetect ()

Sentences ending with an ending character (period, question mark, or ellipsis) can be separated,

Then use the regular expression above to make it more accurate.

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.