-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Hi, I'm trying to incorporate the managed vocabulary endpoint service with Tematres. Tematres has a specialized API for terminology and verb services specifically dedicated to suggesting terms (example: https://vocabularyserver.com/tbci/es/services.php?task=suggestDetails&arg=his&output=json). The Swageer example is available here: https://vocabularyserver.com/apidoc/. There are over 600 vocabularies available in Tematres (https://vocabularyserver.com/vocabularies/).
I tried to copy the Homosaurus schema, but it gives me an error, and I don't know the framework to debug the errors :/
Could someone help me? I'm not sure how to incorporate the endpoint. I'm sharing the code here:
public function getSuggestions($query)
{
$query = trim($query);
if (empty($query) {
return [];
}
try {
$response = $this->client
->setUri('https://vocabularyserver.com/tbci/es/services.php',[
'adapter' => 'Laminas\Http\Client\Adapter\Curl',
])
->setParameterGet([
'task' => 'suggestDetails',
'arg' => $query,
'output' => 'json'
])
->send();
if (!$response->isSuccess()) {
return [];
}
// Parse the JSON response.
$suggestions = [];
$results = json_decode($response->getBody(), true);
if (empty($results) || !is_array($results)) {
return [];
}
foreach ($results as $result) {
if (empty($result['value']) || empty($result['id'])) {
continue;
}
$value = $result['value'];
$id = $result['id'];
$description = $result['description'] ?? '';
$info = '';
if (!empty($description)) {
$info = $description;
}
$suggestions[] = [
'value' => $value . ($info ? ' (' . $info . ')' : ''),
'data' => [
'uri' => $id,
'info' => $info,
],
];
}
return $suggestions;
} catch (\Exception $e) {
// Log error if needed
return [];
}
}