Index: trunk/WikiWord/WikiWord/src/main/php/api.php |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | $result['error'] = array('code' => 1010, 'message' => "failed to connect to thesaurus database"); |
29 | 29 | } else if ($query == 'concepts') { |
30 | 30 | $term = @$_REQUEST['term']; |
31 | | - $page = @$_REQUEST['page']; |
| 31 | + #$page = @$_REQUEST['page']; |
32 | 32 | |
33 | 33 | if ( $lang === null ) $result['error'] = array('code' => 150, 'message' => "missing parameter lang"); |
34 | 34 | else if ( $term !== null ) { |
— | — | @@ -35,14 +35,33 @@ |
36 | 36 | if ( $result['concepts'] === false || $result['concepts'] === null ) { |
37 | 37 | $result['error'] = array('code' => 210, 'message' => "failed to retrieve concepts for term $langt:$term"); |
38 | 38 | } |
39 | | - } else if ( $page !== null ) { |
| 39 | + } /*else if ( $page !== null ) { |
40 | 40 | $result['concepts'] = $thesaurus->getConceptsForPage($lang, $page); |
41 | 41 | if ( $result['concepts'] === false || $result['concepts'] === null ) { |
42 | 42 | $result['error'] = array('code' => 250, 'message' => "failed to retrieve concepts for page $langt:$page"); |
43 | 43 | } |
44 | | - } else { |
| 44 | + } */else { |
45 | 45 | $result['error'] = array('code' => 110, 'message' => "missing parameter term"); |
46 | 46 | } |
| 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 | + } |
47 | 66 | } else if ($query == 'properties') { |
48 | 67 | $gcid = @$_REQUEST['gcid']; |
49 | 68 | if (!$gcid) $gcid = @$_REQUEST['id']; |
Index: trunk/WikiWord/WikiWord/src/main/php/wwthesaurus.php |
— | — | @@ -231,7 +231,7 @@ |
232 | 232 | |
233 | 233 | $pages = array(); |
234 | 234 | foreach ($pp as $p) { |
235 | | - ($t, $n) = explode(":", $p, 2); |
| 235 | + list($t, $n) = explode(":", $p, 2); |
236 | 236 | $pages[$n] = (int)$t; |
237 | 237 | } |
238 | 238 | |
— | — | @@ -243,7 +243,7 @@ |
244 | 244 | |
245 | 245 | $concepts = array(); |
246 | 246 | foreach ($ss as $p) { |
247 | | - ($id, $n) = explode(":", $p, 2); |
| 247 | + list($id, $n) = explode(":", $p, 2); |
248 | 248 | $id = (int)$id; |
249 | 249 | $concepts[$id] = $n; |
250 | 250 | } |
— | — | @@ -255,13 +255,15 @@ |
256 | 256 | function getConceptInfo( $id, $lang = null, $fields = null ) { |
257 | 257 | global $wwTablePrefix, $wwThesaurusDataset, $wwLanguages; |
258 | 258 | |
| 259 | + #TODO: concept cache! |
| 260 | + |
259 | 261 | if ( $fields && is_array($fields)) $fields = implode(", ", $fields); |
260 | 262 | if ( !$fields ) $fields = "*"; |
261 | 263 | |
262 | 264 | #TODO: scores, concept-type, ... |
263 | 265 | |
264 | 266 | $sql = "SELECT $fields FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept_info " |
265 | | - . " WHERE C.id = ".(int)$id; |
| 267 | + . " WHERE concept = ".(int)$id; |
266 | 268 | |
267 | 269 | if ($lang) { |
268 | 270 | if ( is_array($lang) ) $sql .= " AND lang IN " . $this->quoteSet($lang); |
— | — | @@ -288,7 +290,7 @@ |
289 | 291 | $id = null; |
290 | 292 | } |
291 | 293 | |
292 | | - if ($id === null) $id = $row['concept']; |
| 294 | + if ($id === null) $id = (int)$row['concept']; |
293 | 295 | $buff[] = $row; |
294 | 296 | } |
295 | 297 | |
— | — | @@ -300,7 +302,7 @@ |
301 | 303 | $concept["languages"] = array(); |
302 | 304 | |
303 | 305 | foreach ($rows as $row) { |
304 | | - if (!isset($concept["id"])) = $row["concept"]; |
| 306 | + if (!isset($concept["id"])) $concept["id"] = (int)$row["concept"]; |
305 | 307 | |
306 | 308 | $lang = $row["lang"]; |
307 | 309 | $concept["languages"][] = $lang; |
— | — | @@ -316,16 +318,22 @@ |
317 | 319 | if (@$row["similar"] !== null) $concept["similar"][$lang] = $this->splitConcepts($row["similar"]); |
318 | 320 | if (@$row["related"] !== null) $concept["related"][$lang] = $this->splitConcepts($row["related"]); |
319 | 321 | |
| 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 | + |
320 | 327 | if (isset($concept["broader"][$lang])) $concept["broader"]["*"] += array_keys($concept["broader"][$lang]); |
321 | 328 | if (isset($concept["narrower"][$lang])) $concept["narrower"]["*"] += array_keys($concept["narrower"][$lang]); |
322 | 329 | if (isset($concept["similar"][$lang])) $concept["similar"]["*"] += array_keys($concept["similar"][$lang]); |
323 | 330 | if (isset($concept["related"][$lang])) $concept["related"]["*"] += array_keys($concept["related"][$lang]); |
| 331 | + #FIXME: the above doesn't work as expected. what the fuck?! |
324 | 332 | } |
325 | 333 | |
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); |
330 | 338 | |
331 | 339 | return $concept; |
332 | 340 | } |
Index: trunk/WikiWord/WikiWord/src/main/php/concept-info-local.sql |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | -- collect wiki pages |
12 | 12 | update {collection}_{thesaurus}_concept_info as I |
13 | 13 | 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 |
15 | 15 | from {collection}_{thesaurus}_origin as O |
16 | 16 | join {collection}_{lang}_about as A on A.concept = O.local_concept and O.lang = "{lang}" |
17 | 17 | join {collection}_{lang}_resource as R on R.id = A.resource |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | |
25 | 25 | -- collect broader concepts |
26 | 26 | 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 |
28 | 28 | join {collection}_{thesaurus}_origin as O on O.global_concept = broad and O.lang = "{lang}" |
29 | 29 | group by narrow ) as X |
30 | 30 | on X.concept = I.concept and I.lang = "{lang}" |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | |
33 | 33 | -- collect narrower concepts |
34 | 34 | 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 |
36 | 36 | join {collection}_{thesaurus}_origin as O on O.global_concept = narrow and O.lang = "{lang}" |
37 | 37 | group by broad ) as X |
38 | 38 | on X.concept = I.concept and I.lang = "{lang}" |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | |
41 | 41 | -- collect similar concepts |
42 | 42 | 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 |
44 | 44 | join {collection}_{thesaurus}_origin as O on O.global_concept = concept2 and O.lang = "{lang}" |
45 | 45 | where langmatch >= 1 or langref >= 1 |
46 | 46 | group by concept1 ) as X |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | |
50 | 50 | -- collect related concepts |
51 | 51 | 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 |
53 | 53 | join {collection}_{thesaurus}_origin as O on O.global_concept = concept2 and O.lang = "{lang}" |
54 | 54 | where bilink >= 1 |
55 | 55 | group by concept1 ) as X |