Home  >  Article  >  Backend Development  >  English sentence/paragraph

English sentence/paragraph

WBOY
WBOYOriginal
2016-07-25 08:50:441897browse
PHP environment, pointing out a misunderstanding in the original sentence creation. There is no need to consider decimal points or domain names when creating sentences, because standard sentences have spaces after periods. The only thing that needs to be considered is Mr. Li.
The first step is to divide the paragraphs into paragraphs because some quotes end with colons.
  1. /*TWWY'S ART*/
  2. function break_passage($text){ //Split paragraphs
  3. return preg_split("/(r|n|rn)/", $text, -1 , PREG_SPLIT_NO_EMPTY);
  4. }
  5. function break_sentence($text){ //There must be a space after the English period to split sentences
  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){ //First Split paragraphs and then sentences [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. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn