| 1 | Example of [WordNetApi DEBVisDic API] usage in PHP. |
| 2 | |
| 3 | {{{ |
| 4 | #!php |
| 5 | <? |
| 6 | $server = 'https://deb.fi.muni.cz:9001/'; |
| 7 | $user = 'test'; |
| 8 | $password = 'test'; |
| 9 | |
| 10 | $curl = curl_init(); |
| 11 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); |
| 12 | curl_setopt($curl, CURLOPT_USERPWD, $user . ":" . $password); |
| 13 | |
| 14 | #initialize, what dictionaries I have access to? |
| 15 | $url = $server.'doc?action=init'; |
| 16 | curl_setopt($curl, CURLOPT_URL, $url); |
| 17 | $result = curl_exec($curl); |
| 18 | |
| 19 | $dicts = json_decode($result, true); |
| 20 | foreach($dicts['slovniky'] as $dict_code => $dict_info) { |
| 21 | #dictionary code + dictionary url |
| 22 | $dict_url = $dict_info['dict']; |
| 23 | echo $dict_code.':'.$dict_url."\n"; |
| 24 | |
| 25 | #let's search for dogs |
| 26 | $url = $server.$dict_url.'?action=queryList&word=dog'; |
| 27 | curl_setopt($curl, CURLOPT_URL, $url); |
| 28 | $result = curl_exec($curl); |
| 29 | $result_hash = json_decode($result, true); |
| 30 | |
| 31 | #and let's get XML for first three |
| 32 | for($i = 0; $i < 3; $i++) { |
| 33 | $id = $result_hash[$i]['value']; |
| 34 | echo 'Getting XML for '.$result_hash[$i]['label']." with ID=$id\n"; |
| 35 | $url = $server.$dict_url.'?action=runQuery&query='.$id.'&outtype=plain'; |
| 36 | curl_setopt($curl, CURLOPT_URL, $url); |
| 37 | $result = curl_exec($curl); |
| 38 | $xml = json_decode($result); |
| 39 | echo $xml."\n"; |
| 40 | } |
| 41 | } |
| 42 | ?> |
| 43 | }}} |