Example of DEBVisDic API usage in PHP.
Requirements: php-curl and php-json
<? $server = 'https://deb.fi.muni.cz:9001/'; $user = 'test'; $password = 'test'; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_USERPWD, $user . ":" . $password); #initialize, what dictionaries I have access to? $url = $server.'doc?action=connect'; curl_setopt($curl, CURLOPT_URL, $url); $result = curl_exec($curl); $dicts = json_decode($result, true); foreach($dicts['dicts'] as $dict_code => $dict_info) { #dictionary code + dictionary url $dict_url = $dict_info['code']; echo $dict_code.':'.$dict_url."\n"; #let's search for dogs $url = $server.$dict_url.'?action=queryList&word=dog'; curl_setopt($curl, CURLOPT_URL, $url); $result = curl_exec($curl); $result_hash = json_decode($result, true); #and let's get XML for first three for($i = 0; $i < 3; $i++) { $id = $result_hash[$i]['value']; echo 'Getting XML for '.$result_hash[$i]['label']." with ID=$id\n"; $url = $server.$dict_url.'?action=runQuery&query='.$id.'&outtype=plain'; curl_setopt($curl, CURLOPT_URL, $url); $result = curl_exec($curl); $xml = json_decode($result); echo $xml."\n"; } } ?>
Output:
wneng1:wnen Getting XML for [n] African hunting dog:1, hyena dog:1, Cape hunting dog:1, Lycaon pictus:1 with ID=ENG20-02032938-n <SYNSET> <ID>ENG20-02032938-n</ID> <POS>n</POS> <SYNONYM> <LITERAL sense='1'>African hunting dog</LITERAL> <WORD>African</WORD> <WORD>hunting</WORD> <WORD>dog</WORD> <LITERAL sense='1'>hyena dog</LITERAL> <WORD>hyena</WORD> <WORD>dog</WORD> <LITERAL sense='1'>Cape hunting dog</LITERAL> <WORD>Cape</WORD> <WORD>hunting</WORD> <WORD>dog</WORD> <LITERAL sense='1'>Lycaon pictus</LITERAL> <WORD>Lycaon</WORD> <WORD>pictus</WORD> </SYNONYM> <ILR type='hypernym' link='ENG20-02031535-n'>wild dog:1</ILR> <DEF>a powerful doglike mammal of southern and eastern Africa that hunts in large packs; now rare in settled area</DEF> <DOMAIN>zoology</DOMAIN> <SUMO type='+'>Canine</SUMO> </SYNSET> Getting XML for [n] American dog violet:1, Viola conspersa:1 with ID=ENG20-11640058-n <SYNSET> <ID>ENG20-11640058-n</ID> <POS>n</POS> <SYNONYM> <LITERAL sense='1'>American dog violet</LITERAL> <WORD>American</WORD> <WORD>dog</WORD> <WORD>violet</WORD> <LITERAL sense='1'>Viola conspersa</LITERAL> <WORD>Viola</WORD> <WORD>conspersa</WORD> </SYNONYM> <ILR type='hypernym' link='ENG20-11639608-n'>violet:1</ILR> <DEF>violet of eastern North America having pale violet to white flowers</DEF> <DOMAIN>botany</DOMAIN> <SUMO type='+'>FloweringPlant</SUMO> </SYNSET> Getting XML for [n] Bernese mountain dog:1 with ID=ENG20-02024368-n <SYNSET> <ID>ENG20-02024368-n</ID> <POS>n</POS> <SYNONYM> <LITERAL sense='1'>Bernese mountain dog</LITERAL> <WORD>Bernese</WORD> <WORD>mountain</WORD> <WORD>dog</WORD> </SYNONYM> <ILR type='hypernym' link='ENG20-02020367-n'>working dog:1</ILR> <DEF>large powerful long-haired black-coated Swiss dog with deep tan or russet markings on legs and white blaze and feet and chest marking; formerly used for draft</DEF> <DOMAIN>zoology</DOMAIN> <SUMO type='+'>Canine</SUMO> </SYNSET>
Last modified 16 years ago
Last modified on Mar 25, 2008, 12:08:27 PM