1Sentence
2========
3[![License](https://img.shields.io/github/license/vanderlee/php-sentence.svg)]()
4[![Build Status](https://travis-ci.org/vanderlee/php-sentence.svg?branch=master)](https://travis-ci.org/vanderlee/PHPSwaggerGen)
5[![Quality](https://scrutinizer-ci.com/g/vanderlee/php-sentence/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/vanderlee/PHPSwaggerGen)
6
7Version 1.0.7
8
9Copyright © 2016-2022 Martijn van der Lee (@vanderlee), parts copyright © 2017 @marktaw.
10
11MIT Open Source license applies.
12
13## Introduction
14PHP natural language sentence segmentation (splitting) and counting.
15Sentence boundary disambiguation.
16
17Still early, but should support most western languages.
18If you find any problems, please let me know.
19
20Supports PHP 5.3 and up, so you can use it on older servers.
21
22## Installation
23Requires PHP 5.4 or greater. PHP 5.3 is supported as long as no more recent
24features are absolutely necessary.
25
26To install using Composer:
27
28	composer require vanderlee/php-sentence
29
30## Methods
31### ***`integer`*** `count(`***`string`*** `$text)`
32Counts the number of sentences in the text.
33Provided for convenience; this is exactly the same as counting the number of
34returned array items from `split`, so if you need both results, just do that.
35
36### ***`array`*** `split(`***`string`*** `$text, `***`integer`*** `$flags = 0)`
37Splits the text into sentences.
38
39`$flags` is zero (`0`, default) or the following class constant:
40
41-	**`Sentence::SPLIT_TRIM`**: Trim whitespace off the left and right sides of
42	each returned sentence.
43
44## Documentation
45You can find documentation generated from the source code by ApiGen here: [ApiGen documentation](doc/)
46
47# Examples
48	<?php
49
50		// This is the test text we're going to use
51		$text	= "Hello there, Mr. Smith. What're you doing today... Smith,"
52				. " my friend?\n\nI hope it's good. This last sentence will"
53				. " cost you $2.50! Just kidding :)";
54
55		// Create a new instance
56		$Sentence	= new \Sentence;
57
58		// Split into array of sentences
59		$sentences	= $Sentence->split($text);
60
61		// Count the number of sentences
62		$count		= $Sentence->count($text);
63
64	?>
65
66# How it works
67The method used is not based on any on the established or published methods.
68It seems to work pretty well, though.
69
70The method follows a number of simple steps in splitting and re-merging the
71text into full sentences. You can easily check the steps in the code.
72
73Though the splitting may be a bit off, in particular abbreviations at the start
74of sentences tend to be merged with the preceding sentences. In most ordinary
75text this should pose no problem. In either case this should not affect the
76sentence count except in very uncommon situations.
77
78It should be noted that this algorithm depends on reasonably gramatically
79correct punctuation. Do not L33t-5p3ak!!!!!1!1!11!eleven!!
80
81## Rules
82The following is a rough list of the rules used to split sentences.
83
84-	Each linebreak separates sentences.
85-	The end of the text indicates the end if a sentence if not otherwise ended
86	through proper punctuation.
87-	Sentences must be at least two words long, unless a linebreak or end-of-text.
88-	An empty line is not a sentence.
89-	Each question- or exclamation mark or combination thereof, is considered
90	the end of a sentence.
91-	A single period is considered the end of a sentence, unless...
92	-	It is preceded by one word, or...
93	-	It is followed by one word.
94-	A sequence of multiple periods is not considered the end of a sentence.
95
96