@זאביק
אם זה עדיין רלוונטי, כמדומני שזה מה שאתה מבקש.
לא יודע לגבי החוקיות של זה מבחינת תנאי שימוש של האתר.
<?php
header('Content-Type: text/plain; charset=utf-8');
function callDictaAPI($text) {
$url = 'https://nakdan-u1-0.loadbalancer.dicta.org.il/api';
$postData = [
"addmorph" => true,
"keepmetagim" => true,
"keepqq" => false,
"nodageshdefmem" => false,
"patachma" => false,
"task" => "nakdan",
"data" => $text,
"useTokenization" => true,
"genre" => "modern"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$text = $_GET['text'] ?? '';
if (!$text) {
exit("חסר טקסט לשליחה (פרמטר: text)");
}
$result = callDictaAPI($text);
$output = '';
foreach ($result['data'] as $item) {
if (!isset($item['nakdan']['options']) || empty($item['nakdan']['options'])) {
$output .= $item['str'];
continue;
}
$option = null;
foreach ($item['nakdan']['options'] as $opt) {
if (($opt['levelChoice'] ?? null) === 1) {
$option = $opt;
break;
}
}
if (!$option) {
$option = $item['nakdan']['options'][0];
}
$word = $option['w'];
$word = preg_replace('/(?<=\S)\|(?=\S)/u', '', $word);
$output .= $word;
}
echo $output;