Index: trunk/extensions/SemanticResultFormats/ValueRank/SRF_ValueRank.php |
— | — | @@ -15,12 +15,8 @@ |
16 | 16 | class SRFValueRank extends SMWResultPrinter { |
17 | 17 | |
18 | 18 | protected $includeName; |
19 | | - protected $sizeMode; |
20 | | - protected $tagOrder; |
21 | 19 | protected $minCount; |
22 | | - protected $maxSize; |
23 | 20 | protected $maxTags; |
24 | | - protected $minTagSize; |
25 | 21 | |
26 | 22 | protected $tagsHtml = array(); |
27 | 23 | |
— | — | @@ -45,17 +41,13 @@ |
46 | 42 | parent::handleParameters( $params, $outputmode ); |
47 | 43 | |
48 | 44 | $this->includeName = $params['includesubject']; |
49 | | - $this->sizeMode = $params['increase']; |
50 | | - $this->tagOrder = $params['tagorder']; |
51 | 45 | $this->minCount = $params['mincount']; |
52 | 46 | $this->maxTags = $params['maxtags']; |
53 | | - $this->minTagSize = $params['minsize']; |
54 | | - $this->maxSize = $params['maxsize']; |
55 | 47 | } |
56 | 48 | |
57 | 49 | public function getResultText( SMWQueryResult $results, $outputmode ) { |
58 | 50 | $this->isHTML = $outputmode == SMW_OUTPUT_HTML; |
59 | | - return $this->getValueRank( $this->getRank( $this->getTags( $results, $outputmode ) ) ); |
| 51 | + return $this->getVRValueRank( $this->getVRRank( $this->getVRValues( $results, $outputmode ) ) ); |
60 | 52 | } |
61 | 53 | |
62 | 54 | /** |
— | — | @@ -68,7 +60,7 @@ |
69 | 61 | * |
70 | 62 | * @return array |
71 | 63 | */ |
72 | | - protected function getTags( SMWQueryResult $results, $outputmode ) { |
| 64 | + protected function getVRValues( SMWQueryResult $results, $outputmode ) { |
73 | 65 | $tags = array(); |
74 | 66 | |
75 | 67 | while ( /* array of SMWResultArray */ $row = $results->getNext() ) { // Objects (pages) |
— | — | @@ -107,7 +99,6 @@ |
108 | 100 | unset( $tags[$name] ); |
109 | 101 | } |
110 | 102 | } |
111 | | - |
112 | 103 | return $tags; |
113 | 104 | } |
114 | 105 | |
— | — | @@ -121,89 +112,17 @@ |
122 | 113 | * |
123 | 114 | * @return array |
124 | 115 | */ |
125 | | - protected function getRank( array $tags ) { |
| 116 | + protected function getVRRank( array $tags ) { |
126 | 117 | if ( count( $tags ) == 0 ) { |
127 | 118 | return $tags; |
128 | 119 | } |
129 | 120 | |
130 | | - // If the original order needs to be kept, we need a copy of the current order. |
131 | | - if ( $this->tagOrder == 'unchanged' ) { |
132 | | - $unchangedTags = array_keys( $tags ); |
133 | | - } |
134 | | - |
135 | 121 | arsort( $tags, SORT_NUMERIC ); |
136 | 122 | |
137 | 123 | if ( count( $tags ) > $this->maxTags ) { |
138 | 124 | $tags = array_slice( $tags, 0, $this->maxTags, true ); |
139 | 125 | } |
140 | | - |
141 | | - $min = end( $tags ) or $min = 0; |
142 | | - $max = reset( $tags ) or $max = 1; |
143 | | - $maxSizeIncrease = $this->maxSize - $this->minTagSize; |
144 | 126 | |
145 | | - // Loop over the tags, and replace their count by a size. |
146 | | - /* |
147 | | - foreach ( $tags as &$tag ) { |
148 | | - switch ( $this->sizeMode ) { |
149 | | - case 'linear': |
150 | | - $divisor = ($max == $min) ? 1 : $max - $min; |
151 | | - $tag = $this->minTagSize + $maxSizeIncrease * ( $tag -$min ) / $divisor; |
152 | | - break; |
153 | | - case 'log' : default : |
154 | | - $divisor = ($max == $min) ? 1 : log( $max ) - log( $min ); |
155 | | - $tag = $this->minTagSize + $maxSizeIncrease * ( log( $tag ) - log( $min ) ) / $divisor ; |
156 | | - break; |
157 | | - } |
158 | | - } |
159 | | - */ |
160 | | - |
161 | | - switch ( $this->tagOrder ) { |
162 | | - case 'desc' : |
163 | | - // Tags are already sorted desc |
164 | | - break; |
165 | | - case 'asc' : |
166 | | - asort( $tags ); |
167 | | - break; |
168 | | - case 'alphabetical' : |
169 | | - $tagNames = array_keys( $tags ); |
170 | | - natcasesort( $tagNames ); |
171 | | - $newTags = array(); |
172 | | - |
173 | | - foreach ( $tagNames as $name ) { |
174 | | - $newTags[$name] = $tags[$name]; |
175 | | - } |
176 | | - |
177 | | - $tags = $newTags; |
178 | | - break; |
179 | | - case 'random' : |
180 | | - $tagSizes = $tags; |
181 | | - shuffle( $tagSizes ); |
182 | | - $newTags = array(); |
183 | | - |
184 | | - foreach ( $tagSizes as $size ) { |
185 | | - foreach ( $tags as $tagName => $tagSize ) { |
186 | | - if ( $tagSize == $size ) { |
187 | | - $newTags[$tagName] = $tags[$tagName]; |
188 | | - break; |
189 | | - } |
190 | | - } |
191 | | - } |
192 | | - |
193 | | - $tags = $newTags; |
194 | | - break; |
195 | | - case 'unchanged' : default : // Restore the original order. |
196 | | - $changedTags = $tags; |
197 | | - $tags = array(); |
198 | | - |
199 | | - foreach ( $unchangedTags as $name ) { |
200 | | - // Original tags might have been left out at this point, so only add remaining ones. |
201 | | - if ( array_key_exists( $name, $changedTags ) ) { |
202 | | - $tags[$name] = $changedTags[$name]; |
203 | | - } |
204 | | - } |
205 | | - break; |
206 | | - } |
207 | | - |
208 | 127 | return $tags; |
209 | 128 | } |
210 | 129 | |
— | — | @@ -216,19 +135,19 @@ |
217 | 136 | * |
218 | 137 | * @return string |
219 | 138 | */ |
220 | | - protected function getValueRank( array $tags ) { |
| 139 | + protected function getVRValueRank( array $tags ) { |
221 | 140 | $htmlTags = array(); |
222 | 141 | |
223 | 142 | foreach ( $tags as $name => $size ) { |
224 | 143 | $htmlTags[] = Html::rawElement( |
225 | 144 | 'li', |
226 | | - array( 'style' => "font-size:100%" ), |
227 | | - $this->tagsHtml[$name . '(' . $size . ')'] |
| 145 | + array( 'style' => "font-size:$size" ), |
| 146 | + $this->tagsHtml[$name] . ' (' . $size . ')' |
228 | 147 | ); |
229 | 148 | } |
230 | 149 | |
231 | 150 | return Html::rawElement( |
232 | | - 'ul', |
| 151 | + 'ol', |
233 | 152 | array( 'align' => 'left' ), |
234 | 153 | implode( ' ', $htmlTags ) |
235 | 154 | ); |
— | — | @@ -248,16 +167,6 @@ |
249 | 168 | $params['includesubject']->setMessage( 'srf_paramdesc_includesubject' ); |
250 | 169 | $params['includesubject']->setDefault( false ); |
251 | 170 | |
252 | | - $params['increase'] = new Parameter( 'increase' ); |
253 | | - $params['increase']->setMessage( 'srf_paramdesc_increase' ); |
254 | | - $params['increase']->addCriteria( new CriterionInArray( 'linear', 'log' ) ); |
255 | | - $params['increase']->setDefault( 'log' ); |
256 | | - |
257 | | - $params['tagorder'] = new Parameter( 'tagorder' ); |
258 | | - $params['tagorder']->setMessage( 'srf_paramdesc_tagorder' ); |
259 | | - $params['tagorder']->addCriteria( new CriterionInArray( 'alphabetical', 'asc', 'desc', 'random', 'unchanged' ) ); |
260 | | - $params['tagorder']->setDefault( 'desc' ); |
261 | | - |
262 | 171 | $params['mincount'] = new Parameter( 'mincount', Parameter::TYPE_INTEGER ); |
263 | 172 | $params['mincount']->setMessage( 'srf_paramdesc_mincount' ); |
264 | 173 | $params['mincount']->setDefault( 1 ); |
— | — | @@ -265,16 +174,8 @@ |
266 | 175 | $params['maxtags'] = new Parameter( 'maxtags', Parameter::TYPE_INTEGER ); |
267 | 176 | $params['maxtags']->setMessage( 'srf_paramdesc_maxtags' ); |
268 | 177 | $params['maxtags']->setDefault( 1000 ); |
269 | | - |
270 | | - $params['minsize'] = new Parameter( 'minsize', Parameter::TYPE_INTEGER ); |
271 | | - $params['minsize']->setMessage( 'srf_paramdesc_minsize' ); |
272 | | - $params['minsize']->setDefault( 77 ); |
273 | | - |
274 | | - $params['maxsize'] = new Parameter( 'maxsize', Parameter::TYPE_INTEGER ); |
275 | | - $params['maxsize']->setMessage( 'srf_paramdesc_maxsize' ); |
276 | | - $params['maxsize']->setDefault( 242 ); |
277 | 178 | |
278 | 179 | return $params; |
279 | | - } |
| 180 | + } |
280 | 181 | |
281 | 182 | } |