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 | 22 | public function tag($text) |
|
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $token |
||
| 67 | * @return bool |
||
| 68 | */ |
||
| 69 | 23 | public function tokenExists($token) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * @param string $tag |
||
| 76 | * @return bool |
||
| 77 | */ |
||
| 78 | 22 | public function isNoun($tag) |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @param string $tag |
||
| 85 | * @return bool |
||
| 86 | */ |
||
| 87 | 16 | public function isProperNoun($tag) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * @param string $tag |
||
| 94 | * @return bool |
||
| 95 | */ |
||
| 96 | 14 | public function isSingularNoun($tag) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * @param string $tag |
||
| 103 | * @param string $token |
||
| 104 | * @return bool |
||
| 105 | */ |
||
| 106 | 16 | public function isPluralNoun($tag, $token) |
|
| 110 | |||
| 111 | /** |
||
| 112 | * @param string $tag |
||
| 113 | * @return bool |
||
| 114 | */ |
||
| 115 | 2 | public function isVerb($tag) |
|
| 119 | |||
| 120 | /** |
||
| 121 | * @param string $tag |
||
| 122 | * @return bool |
||
| 123 | */ |
||
| 124 | 1 | public function isPronoun($tag) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @param string $token |
||
| 131 | * @return bool |
||
| 132 | */ |
||
| 133 | 4 | public function isPastTenseVerb($token) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * @param string $token |
||
| 140 | * @return bool |
||
| 141 | */ |
||
| 142 | 4 | public function isPresentTenseVerb($token) |
|
| 146 | |||
| 147 | /** it him me us you 'em thee we'uns |
||
| 148 | * |
||
| 149 | * @param string $tag |
||
| 150 | * @return bool |
||
| 151 | */ |
||
| 152 | 1 | public function isAccusativePronoun($tag) |
|
| 156 | |||
| 157 | /** it he she thee |
||
| 158 | * |
||
| 159 | * @param string $tag |
||
| 160 | * @return bool |
||
| 161 | */ |
||
| 162 | 1 | public function isThirdPersonPronoun($tag) |
|
| 166 | |||
| 167 | /** they we I you ye thou you'uns |
||
| 168 | * |
||
| 169 | * @param string $tag |
||
| 170 | * @return bool |
||
| 171 | */ |
||
| 172 | 1 | public function isSingularPersonalPronoun($tag) |
|
| 176 | |||
| 177 | /** itself himself myself yourself herself oneself ownself |
||
| 178 | * |
||
| 179 | * @param string $tag |
||
| 180 | * @return bool |
||
| 181 | */ |
||
| 182 | 1 | public function isSingularReflexivePronoun($tag) |
|
| 186 | |||
| 187 | /** themselves ourselves yourselves |
||
| 188 | * |
||
| 189 | * @param string $tag |
||
| 190 | * @return bool |
||
| 191 | */ |
||
| 192 | 1 | public function isPluralReflexivePronoun($tag) |
|
| 196 | |||
| 197 | /** ours mine his her/hers their/theirs our its my your/yours out thy thine |
||
| 198 | * |
||
| 199 | * @param string $tag |
||
| 200 | * @return bool |
||
| 201 | */ |
||
| 202 | 1 | public function isPossessivePronoun($tag) |
|
| 206 | |||
| 207 | /** |
||
| 208 | * @param string $token |
||
| 209 | * @return bool |
||
| 210 | */ |
||
| 211 | 17 | public function isAdjective($token) |
|
| 215 | |||
| 216 | /** |
||
| 217 | * @param string $token |
||
| 218 | * @return bool |
||
| 219 | */ |
||
| 220 | 17 | public function isGerund($token) |
|
| 224 | |||
| 225 | /** |
||
| 226 | * @param string $token |
||
| 227 | * @return bool |
||
| 228 | */ |
||
| 229 | 17 | public function isPastParticiple($token) |
|
| 233 | |||
| 234 | /** |
||
| 235 | * @param string $token |
||
| 236 | * @return bool |
||
| 237 | */ |
||
| 238 | 23 | public function isAdverb($token) |
|
| 242 | |||
| 243 | /** Common noun to adj. if it ends with 'al', |
||
| 244 | * to gerund if 'ing', to past tense if 'ed' |
||
| 245 | * |
||
| 246 | * @param string $tag |
||
| 247 | * @param string $token |
||
| 248 | * @return string |
||
| 249 | */ |
||
| 250 | 16 | public function transformNoun($tag, $token) |
|
| 272 | |||
| 273 | /** |
||
| 274 | * @param array $tags |
||
| 275 | * @param int $i |
||
| 276 | * @param string $token |
||
| 277 | * @return mixed |
||
| 278 | */ |
||
| 279 | 13 | public function transformNounToVerb($tags, $i, $token) |
|
| 300 | |||
| 301 | /** |
||
| 302 | * @param array $tags |
||
| 303 | * @param int $i |
||
| 304 | * @return mixed |
||
| 305 | */ |
||
| 306 | 13 | public function transformVerbToNoun($tags, $i) |
|
| 315 | |||
| 316 | /** |
||
| 317 | * @param string $tag |
||
| 318 | * @param string $token |
||
| 319 | * @return string |
||
| 320 | */ |
||
| 321 | 22 | public function transformNumerics($tag, $token) |
|
| 340 | } |
||
| 341 |