-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadability.php
110 lines (91 loc) · 3.05 KB
/
Readability.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/* Readability.php
*
* Copyright 2009 Julian Calaby <julian.calaby@gmail.com>
*
* This file is based upon style.c from GNU Diction.
*
* GNU Diction is GNU software, copyright 1997-2007
* Michael Haardt <michael@moria.de>.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
require_once("Style.php");
class Readability extends Style {
function kincaid() {
return 11.8 * ($this->syllables / $this->words) + 0.39 * ($this->words / $this->sentences) - 15.59;
}
function ari() {
return 4.71 * ($this->characters / $this->words) + 0.5 * ($this->words / $this->sentences) - 21.43;
}
function coleman_liau() {
return 5.879851 * ($this->characters / $this->words) - 29.587280 * ($this->sentences / $this->words) - 15.800804;
}
function flesch() {
return 206.835 - 84.6 * ($this->syllables / $this->words) - 1.015 * ($this->words / $this->sentences);
}
function fog() {
return 0.4 * ($this->words / $this->sentences + 100.0 * $this->bigwords / $this->words);
}
function wstf() {
return 0.1935 * ($this->bigwords / $this->words) + 0.1672 * ($this->words / $this->sentences) - 0.1297 * ($this->longwords / $this->words) - 0.0327 * ($this->shortwords / $this->words) - 0.875;
}
function wheeler_smith() {
$idx = ($this->words / $this->sentences) * 10.0 * ($this->bigwords / $this->words);
$grade = 99;
if ($idx <= 16)
$grade = 0;
else if ($idx <= 20)
$grade = 5;
else if ($idx <= 24)
$grade = 6;
else if ($idx <= 29)
$grade = 7;
else if ($idx <= 34)
$grade = 8;
else if ($idx <= 38)
$grade = 9;
else if ($idx <= 42)
$grade = 10;
return array("_value" => $idx, "grade" => $grade);
}
function lix() {
$idx = ($this->words / $this->sentences) + 100.0 * ($this->longwords / $this->words);
$grade = 99;
if ($idx < 34)
$grade = 0;
else if ($idx < 38)
$grade = 5;
else if ($idx < 41)
$grade = 6;
else if ($idx < 44)
$grade = 7;
else if ($idx < 48)
$grade = 8;
else if ($idx < 51)
$grade = 9;
else if ($idx < 54)
$grade = 10;
else if ($idx < 57)
$grade = 11;
return array("_value" => $idx, "grade" => $grade);
}
function smog() {
if( get_class($this->lang) == "LangDE" )
return sqrt(30.0 * ($this->bigwords / $this->sentences)) - 2.0;
return sqrt(30.0 * ($this->bigwords / $this->sentences)) + 3.0;
}
}
?>