Example of [WordNetApi DEBVisDic API] usage in PHP.
Requirements: [http://cz.php.net/manual/en/ref.curl.php php-curl] and [http://cz.php.net/manual/en/ref.json.php php-json]
{{{
#!php
$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
ENG20-02032938-n
n
African hunting dog
African
hunting
dog
hyena dog
hyena
dog
Cape hunting dog
Cape
hunting
dog
Lycaon pictus
Lycaon
pictus
wild dog:1
a powerful doglike mammal of southern and eastern Africa that hunts in large packs; now rare in settled area
zoology
Canine
Getting XML for [n] American dog violet:1, Viola conspersa:1 with ID=ENG20-11640058-n
ENG20-11640058-n
n
American dog violet
American
dog
violet
Viola conspersa
Viola
conspersa
violet:1
violet of eastern North America having pale violet to white flowers
botany
FloweringPlant
Getting XML for [n] Bernese mountain dog:1 with ID=ENG20-02024368-n
ENG20-02024368-n
n
Bernese mountain dog
Bernese
mountain
dog
working dog:1
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
zoology
Canine
}}}