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 | 12 | public function tag($text) { |
|
| 111 | |||
| 112 | 3 | public function tokenExists($token){ |
|
| 115 | |||
| 116 | 12 | public function isNoun($tag) { |
|
| 119 | |||
| 120 | 12 | public function isSingularNoun($tag){ |
|
| 123 | |||
| 124 | 12 | public function isPluralNoun($tag, $token) { |
|
| 127 | |||
| 128 | 1 | public function isVerb($tag) { |
|
| 131 | |||
| 132 | public function isPronoun($tag) { |
||
| 135 | |||
| 136 | 3 | public function isPastTenseVerb($token) { |
|
| 139 | |||
| 140 | 3 | public function isPresentTenseVerb($token) { |
|
| 143 | |||
| 144 | # it him me us you 'em thee we'uns |
||
| 145 | public function isAccusativePronoun($tag) { |
||
| 148 | |||
| 149 | # it he she thee |
||
| 150 | public function isThirdPersonPronoun($tag) { |
||
| 153 | |||
| 154 | # they we I you ye thou you'uns |
||
| 155 | public function isSingularPersonalPronoun($tag) { |
||
| 158 | |||
| 159 | # itself himself myself yourself herself oneself ownself |
||
| 160 | public function isSingularReflexivePronoun($tag) { |
||
| 163 | |||
| 164 | # themselves ourselves yourselves |
||
| 165 | public function isPluralReflexivePronoun($tag) { |
||
| 168 | |||
| 169 | # ours mine his her/hers their/theirs our its my your/yours out thy thine |
||
| 170 | public function isPossessivePronoun($tag) { |
||
| 173 | |||
| 174 | 11 | public function isAdjective($token) { |
|
| 177 | |||
| 178 | 11 | public function isGerund($token) { |
|
| 181 | |||
| 182 | 11 | public function isPastParticiple($token) { |
|
| 185 | |||
| 186 | 12 | public function isAdverb($token){ |
|
| 189 | } |
||
| 190 |