r62878 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62877‎ | r62878 | r62879 >
Date:17:08, 23 February 2010
Author:daniel
Status:deferred
Tags:
Comment:
wikiword web api update; client code now incompatible
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/php/api.php (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/php/concept-info-local.sql (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/php/wwthesaurus.php (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/php/api.php
@@ -27,7 +27,7 @@
2828 $result['error'] = array('code' => 1010, 'message' => "failed to connect to thesaurus database");
2929 } else if ($query == 'concepts') {
3030 $term = @$_REQUEST['term'];
31 - $page = @$_REQUEST['page'];
 31+ #$page = @$_REQUEST['page'];
3232
3333 if ( $lang === null ) $result['error'] = array('code' => 150, 'message' => "missing parameter lang");
3434 else if ( $term !== null ) {
@@ -35,14 +35,33 @@
3636 if ( $result['concepts'] === false || $result['concepts'] === null ) {
3737 $result['error'] = array('code' => 210, 'message' => "failed to retrieve concepts for term $langt:$term");
3838 }
39 - } else if ( $page !== null ) {
 39+ } /*else if ( $page !== null ) {
4040 $result['concepts'] = $thesaurus->getConceptsForPage($lang, $page);
4141 if ( $result['concepts'] === false || $result['concepts'] === null ) {
4242 $result['error'] = array('code' => 250, 'message' => "failed to retrieve concepts for page $langt:$page");
4343 }
44 - } else {
 44+ } */else {
4545 $result['error'] = array('code' => 110, 'message' => "missing parameter term");
4646 }
 47+ } else if ($query == 'concept' || $query == 'info') {
 48+ $gcid = @$_REQUEST['gcid'];
 49+ if (!$gcid) $gcid = @$_REQUEST['id'];
 50+
 51+ $lang = @$_REQUEST['lang'];
 52+
 53+ if ( $gcid === null ) {
 54+ $result['error'] = array('code' => 120, 'message' => "missing parameter gcid");
 55+ } else {
 56+ if ($lang) {
 57+ $lang = preg_split('![\\s,;|/:]\\s*!', $lang);
 58+ if (count($lang) == 1) $lang = $lang[0];
 59+ }
 60+
 61+ $result['concept'] = $thesaurus->getConceptInfo($gcid, $lang);
 62+ if ( $result['concept'] === false || $result['concept'] === null ) {
 63+ $result['error'] = array('code' => 210, 'message' => "concept not found: $gcid");
 64+ }
 65+ }
4766 } else if ($query == 'properties') {
4867 $gcid = @$_REQUEST['gcid'];
4968 if (!$gcid) $gcid = @$_REQUEST['id'];
Index: trunk/WikiWord/WikiWord/src/main/php/wwthesaurus.php
@@ -231,7 +231,7 @@
232232
233233 $pages = array();
234234 foreach ($pp as $p) {
235 - ($t, $n) = explode(":", $p, 2);
 235+ list($t, $n) = explode(":", $p, 2);
236236 $pages[$n] = (int)$t;
237237 }
238238
@@ -243,7 +243,7 @@
244244
245245 $concepts = array();
246246 foreach ($ss as $p) {
247 - ($id, $n) = explode(":", $p, 2);
 247+ list($id, $n) = explode(":", $p, 2);
248248 $id = (int)$id;
249249 $concepts[$id] = $n;
250250 }
@@ -255,13 +255,15 @@
256256 function getConceptInfo( $id, $lang = null, $fields = null ) {
257257 global $wwTablePrefix, $wwThesaurusDataset, $wwLanguages;
258258
 259+ #TODO: concept cache!
 260+
259261 if ( $fields && is_array($fields)) $fields = implode(", ", $fields);
260262 if ( !$fields ) $fields = "*";
261263
262264 #TODO: scores, concept-type, ...
263265
264266 $sql = "SELECT $fields FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept_info "
265 - . " WHERE C.id = ".(int)$id;
 267+ . " WHERE concept = ".(int)$id;
266268
267269 if ($lang) {
268270 if ( is_array($lang) ) $sql .= " AND lang IN " . $this->quoteSet($lang);
@@ -288,7 +290,7 @@
289291 $id = null;
290292 }
291293
292 - if ($id === null) $id = $row['concept'];
 294+ if ($id === null) $id = (int)$row['concept'];
293295 $buff[] = $row;
294296 }
295297
@@ -300,7 +302,7 @@
301303 $concept["languages"] = array();
302304
303305 foreach ($rows as $row) {
304 - if (!isset($concept["id"])) = $row["concept"];
 306+ if (!isset($concept["id"])) $concept["id"] = (int)$row["concept"];
305307
306308 $lang = $row["lang"];
307309 $concept["languages"][] = $lang;
@@ -316,16 +318,22 @@
317319 if (@$row["similar"] !== null) $concept["similar"][$lang] = $this->splitConcepts($row["similar"]);
318320 if (@$row["related"] !== null) $concept["related"][$lang] = $this->splitConcepts($row["related"]);
319321
 322+ if (isset($concept["broader"][$lang]) && !isset($concept["broader"]["*"])) $concept["broader"]["*"] = array();
 323+ if (isset($concept["narrower"][$lang]) && !isset($concept["narrower"]["*"])) $concept["narrower"]["*"] = array();
 324+ if (isset($concept["similar"][$lang]) && !isset($concept["similar"]["*"])) $concept["similar"]["*"] = array();
 325+ if (isset($concept["related"][$lang]) && !isset($concept["related"]["*"])) $concept["related"]["*"] = array();
 326+
320327 if (isset($concept["broader"][$lang])) $concept["broader"]["*"] += array_keys($concept["broader"][$lang]);
321328 if (isset($concept["narrower"][$lang])) $concept["narrower"]["*"] += array_keys($concept["narrower"][$lang]);
322329 if (isset($concept["similar"][$lang])) $concept["similar"]["*"] += array_keys($concept["similar"][$lang]);
323330 if (isset($concept["related"][$lang])) $concept["related"]["*"] += array_keys($concept["related"][$lang]);
 331+ #FIXME: the above doesn't work as expected. what the fuck?!
324332 }
325333
326 - if (isset($concept["broader"]["*"])) $concept["broader"]["*"] = array_unique($concept["broader"]["*"]);
327 - if (isset($concept["narrower"]["*"])) $concept["narrower"]["*"] = array_unique($concept["narrower"]["*"]);
328 - if (isset($concept["similar"]["*"])) $concept["similar"]["*"] = array_unique($concept["similar"]["*"]);
329 - if (isset($concept["broader"]["*"])) $concept["related"]["*"] = array_unique($concept["related"]["*"]);
 334+ if (isset($concept["broader"]["*"])) $concept["broader"]["*"] = array_unique($concept["broader"]["*"], SORT_NUMERIC);
 335+ if (isset($concept["narrower"]["*"])) $concept["narrower"]["*"] = array_unique($concept["narrower"]["*"], SORT_NUMERIC);
 336+ if (isset($concept["similar"]["*"])) $concept["similar"]["*"] = array_unique($concept["similar"]["*"], SORT_NUMERIC);
 337+ if (isset($concept["broader"]["*"])) $concept["related"]["*"] = array_unique($concept["related"]["*"], SORT_NUMERIC);
330338
331339 return $concept;
332340 }
Index: trunk/WikiWord/WikiWord/src/main/php/concept-info-local.sql
@@ -10,7 +10,7 @@
1111 -- collect wiki pages
1212 update {collection}_{thesaurus}_concept_info as I
1313 join ( select O.global_concept as concept, O.lang as lang,
14 - group_concat( concat(R.type, ":", R.name) separator "|" ) as pages
 14+ group_concat(distinct concat(R.type, ":", R.name) separator "|" ) as pages
1515 from {collection}_{thesaurus}_origin as O
1616 join {collection}_{lang}_about as A on A.concept = O.local_concept and O.lang = "{lang}"
1717 join {collection}_{lang}_resource as R on R.id = A.resource
@@ -23,7 +23,7 @@
2424
2525 -- collect broader concepts
2626 update {collection}_{thesaurus}_concept_info as I
27 -join ( select narrow as concept, group_concat(concat(broad, ":", local_concept_name) separator "|") as broader from {collection}_{thesaurus}_broader
 27+join ( select narrow as concept, group_concat(distinct concat(broad, ":", local_concept_name) separator "|") as broader from {collection}_{thesaurus}_broader
2828 join {collection}_{thesaurus}_origin as O on O.global_concept = broad and O.lang = "{lang}"
2929 group by narrow ) as X
3030 on X.concept = I.concept and I.lang = "{lang}"
@@ -31,7 +31,7 @@
3232
3333 -- collect narrower concepts
3434 update {collection}_{thesaurus}_concept_info as I
35 -join ( select broad as concept, group_concat(concat(narrow, ":", local_concept_name) separator "|") as narrower from {collection}_{thesaurus}_broader
 35+join ( select broad as concept, group_concat(distinct concat(narrow, ":", local_concept_name) separator "|") as narrower from {collection}_{thesaurus}_broader
3636 join {collection}_{thesaurus}_origin as O on O.global_concept = narrow and O.lang = "{lang}"
3737 group by broad ) as X
3838 on X.concept = I.concept and I.lang = "{lang}"
@@ -39,7 +39,7 @@
4040
4141 -- collect similar concepts
4242 update {collection}_{thesaurus}_concept_info as I
43 -join ( select concept1 as concept, group_concat(concat(concept2, ":", local_concept_name) separator "|") as similar from {collection}_{thesaurus}_relation
 43+join ( select concept1 as concept, group_concat(distinct concat(concept2, ":", local_concept_name) separator "|") as similar from {collection}_{thesaurus}_relation
4444 join {collection}_{thesaurus}_origin as O on O.global_concept = concept2 and O.lang = "{lang}"
4545 where langmatch >= 1 or langref >= 1
4646 group by concept1 ) as X
@@ -48,7 +48,7 @@
4949
5050 -- collect related concepts
5151 update {collection}_{thesaurus}_concept_info as I
52 -join ( select concept1 as concept, group_concat(concat(concept2, ":", local_concept_name) separator "|") as related from {collection}_{thesaurus}_relation
 52+join ( select concept1 as concept, group_concat(distinct concat(concept2, ":", local_concept_name) separator "|") as related from {collection}_{thesaurus}_relation
5353 join {collection}_{thesaurus}_origin as O on O.global_concept = concept2 and O.lang = "{lang}"
5454 where bilink >= 1
5555 group by concept1 ) as X

Status & tagging log