English sentence/paragraph

Source: Internet
Author: User
Sub-sentences and paragraphs
In the php environment, I pointed out a misunderstanding of the original clause. the decimal point and domain name are not considered for the clause. because the standard sentence is followed by a space, the only thing to consider is Mr. li.
The section-based approach is to consider that some references end with a colon.

  1. /* TWWY's ART */
  2. Function break_passage ($ text) {// split a paragraph
  3. Return preg_split ("/(\ r | \ n | \ r \ n)/", $ text,-1, PREG_SPLIT_NO_EMPTY );
  4. }
  5. Function break_sentence ($ text) {// separate sentences with spaces after the English periods
  6. $ Re = '/# Split sentences on whitespace between them.
  7. (? <= # Begin positive lookbehind.
  8. [.!?] # Either an end of sentence punct,
  9. | [.!?] [\ '"] # Or end of sentence punct and quote.
  10. ) # End positive lookbehind.
  11. (? Mr \. # Skip either "Mr ."
  12. | Mrs \. # or "Mrs .",
  13. | Ms \. # or "Ms .",
  14. | Jr \. # or "Jr .",
  15. | Dr \. # or "Dr .",
  16. | Prof \. # or "Prof .",
  17. | Sr \. # or "Sr .",
  18. # Or... (you get the idea ).
  19. ) # End negative lookbehind.
  20. \ S + # Split on whitespace between sentences.
  21. /Ix ';
  22. $ Sentences = preg_split ($ re, $ text,-1, PREG_SPLIT_NO_EMPTY );
  23. Return $ sentences;
  24. }
  25. Function get_sentence ($ text) {// splits a paragraph before dividing a sentence. [recommended]
  26. $ Passage = break_passage ($ text );
  27. $ Return = array ();
  28. Foreach ($ passage as $ key => $ value) $ return = array_merge ($ return, break_sentence ($ value ));
  29. Return $ return;
  30. }
  31. ?>

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.