首页 >后端开发 >php教程 >英文分句/分段落

英文分句/分段落

WBOY
WBOY原创
2016-07-25 08:50:441950浏览
php环境,指出一个原本分句的时候的误区,分句不用考虑小数点,不用考虑域名,因为标准的句子是句号后面加空格的,唯一要考虑的就是Mr. Li 这种。
先采用分段落的方式是考虑到有些引用采用冒号结尾。
  1. /*TWWY'S ART*/
  2. function break_passage($text){ //分割段落
  3. return preg_split("/(\r|\n|\r\n)/", $text, -1, PREG_SPLIT_NO_EMPTY);
  4. }
  5. function break_sentence($text){ //分割句子 英文的句号后面必须有空格
  6. $re = '/# Split sentences on whitespace between them.
  7. (? [.!?] # Either an end of sentence punct,
  8. | [.!?][\'"] # or end of sentence punct and quote.
  9. ) # End positive lookbehind.
  10. (? Mr\. # Skip either "Mr."
  11. | Mrs\. # or "Mrs.",
  12. | Ms\. # or "Ms.",
  13. | Jr\. # or "Jr.",
  14. | Dr\. # or "Dr.",
  15. | Prof\. # or "Prof.",
  16. | Sr\. # or "Sr.",
  17. # or... (you get the idea).
  18. ) # End negative lookbehind.
  19. \s+ # Split on whitespace between sentences.
  20. /ix';
  21. $sentences = preg_split($re, $text, -1, PREG_SPLIT_NO_EMPTY);
  22. return $sentences;
  23. }
  24. function get_sentence($text){ //先分割段落再分割句子 [推荐]
  25. $passage = break_passage($text);
  26. $return = array();
  27. foreach ($passage as $key => $value) $return = array_merge($return, break_sentence($value));
  28. return $return;
  29. }
  30. ?>
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn