Complex classes like BrillTagger often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BrillTagger, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class BrillTagger |
||
| 14 | { |
||
| 15 | private $dictionary = LEXICON; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param $text |
||
| 19 | * @return array |
||
| 20 | */ |
||
| 21 | 31 | public function tag($text) { |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @param string $token |
||
| 69 | * @return bool |
||
| 70 | */ |
||
| 71 | 32 | public function tokenExists($token) { |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @param string $tag |
||
| 77 | * @return bool |
||
| 78 | */ |
||
| 79 | 31 | public function isNoun($tag) { |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @param string $tag |
||
| 85 | * @return bool |
||
| 86 | */ |
||
| 87 | 10 | public function isSingularNoun($tag) { |
|
| 90 | |||
| 91 | /** |
||
| 92 | * @param string $tag |
||
| 93 | * @param string $token |
||
| 94 | * @return bool |
||
| 95 | */ |
||
| 96 | 17 | public function isPluralNoun($tag, $token) { |
|
| 99 | |||
| 100 | /** |
||
| 101 | * @param string $tag |
||
| 102 | * @return bool |
||
| 103 | */ |
||
| 104 | 22 | public function isVerb($tag) { |
|
| 107 | |||
| 108 | /** |
||
| 109 | * @param string $tag |
||
| 110 | * @return bool |
||
| 111 | */ |
||
| 112 | 18 | public function isVerbToHave($tag) { |
|
| 115 | |||
| 116 | /** |
||
| 117 | * @param string $tag |
||
| 118 | * @return bool |
||
| 119 | */ |
||
| 120 | 1 | public function isPronoun($tag) { |
|
| 123 | |||
| 124 | /** |
||
| 125 | * @param string $token |
||
| 126 | * @return bool |
||
| 127 | */ |
||
| 128 | 4 | public function isPastTenseVerb($token) { |
|
| 131 | |||
| 132 | /** |
||
| 133 | * @param string $token |
||
| 134 | * @return bool |
||
| 135 | */ |
||
| 136 | 4 | public function isPresentTenseVerb($token) { |
|
| 139 | |||
| 140 | /** it him me us you 'em thee we'uns |
||
| 141 | * @param string $tag |
||
| 142 | * @return bool |
||
| 143 | */ |
||
| 144 | 1 | public function isAccusativePronoun($tag) { |
|
| 147 | |||
| 148 | /** it he she thee |
||
| 149 | * @param string $tag |
||
| 150 | * @return bool |
||
| 151 | */ |
||
| 152 | 1 | public function isThirdPersonPronoun($tag) { |
|
| 155 | |||
| 156 | /** they we I you ye thou you'uns |
||
| 157 | * @param string $tag |
||
| 158 | * @return bool |
||
| 159 | */ |
||
| 160 | 1 | public function isSingularPersonalPronoun($tag) { |
|
| 163 | |||
| 164 | /** itself himself myself yourself herself oneself ownself |
||
| 165 | * @param string $tag |
||
| 166 | * @return bool |
||
| 167 | */ |
||
| 168 | 1 | public function isSingularReflexivePronoun($tag) { |
|
| 171 | |||
| 172 | /** themselves ourselves yourselves |
||
| 173 | * @param string $tag |
||
| 174 | * @return bool |
||
| 175 | */ |
||
| 176 | 1 | public function isPluralReflexivePronoun($tag) { |
|
| 179 | |||
| 180 | /** ours mine his her/hers their/theirs our its my your/yours out thy thine |
||
| 181 | * @param string $tag |
||
| 182 | * @return bool |
||
| 183 | */ |
||
| 184 | 1 | public function isPossessivePronoun($tag) { |
|
| 187 | |||
| 188 | /** |
||
| 189 | * @param string $token |
||
| 190 | * @return bool |
||
| 191 | */ |
||
| 192 | 21 | public function isAdjective($token) { |
|
| 195 | |||
| 196 | /** |
||
| 197 | * @param string $token |
||
| 198 | * @return bool |
||
| 199 | */ |
||
| 200 | 21 | public function isGerund($token) { |
|
| 203 | |||
| 204 | /** |
||
| 205 | * @param string $token |
||
| 206 | * @return bool |
||
| 207 | */ |
||
| 208 | 21 | public function isPastParticiple($token) { |
|
| 211 | |||
| 212 | /** |
||
| 213 | * @param string $token |
||
| 214 | * @return bool |
||
| 215 | */ |
||
| 216 | 32 | public function isAdverb($token) { |
|
| 219 | |||
| 220 | /** Common noun to adj. if it ends with 'al', |
||
| 221 | * to gerund if 'ing', to past tense if 'ed' |
||
| 222 | * |
||
| 223 | * @param string $tag |
||
| 224 | * @param string $token |
||
| 225 | * @return string |
||
| 226 | */ |
||
| 227 | 20 | public function transformNoun($tag, $token) { |
|
| 248 | |||
| 249 | /** |
||
| 250 | * @param array $tags |
||
| 251 | * @param int $i |
||
| 252 | * @param string $token |
||
| 253 | * @return mixed |
||
| 254 | */ |
||
| 255 | 9 | public function transformNounToVerb($tags, $i, $token) { |
|
| 275 | |||
| 276 | /** |
||
| 277 | * @param array $tags |
||
| 278 | * @param int $i |
||
| 279 | * @return mixed |
||
| 280 | */ |
||
| 281 | 9 | public function transformVerbToNoun($tags, $i) { |
|
| 289 | |||
| 290 | /** |
||
| 291 | * @param string $tag |
||
| 292 | * @param string $token |
||
| 293 | * @return string |
||
| 294 | */ |
||
| 295 | 31 | public function transformNumerics($tag, $token) { |
|
| 313 | |||
| 314 | 10 | public function transformVerbsToThirdPerson($tag, $token) { |
|
| 338 | } |
||
| 339 |