diff --git a/scripts/videoplayer.js b/scripts/videoplayer.js index edc6167..5dc4822 100644 --- a/scripts/videoplayer.js +++ b/scripts/videoplayer.js @@ -22,6 +22,28 @@ let autoPlayEnabled = true; let currentTranslationMode = 'letters'; // Default mode translateBtn.disabled = true; +// Function to lemmatize text via NLP4SK API +async function lemmatizeText(text) { + try { + const response = await fetch('http://arl6.library.sk/nlp4sk/api/lematizacia', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ text }), + }); + + if (!response.ok) { + throw new Error('Chyba pri volaní lematizačného API'); + } + + const data = await response.json(); + return data.result || text; // Return lemmatized text or original if no result + } catch (error) { + console.error('Chyba pri lematizácii:', error); + statusText.innerText = 'Chyba pri lematizácii, použije sa pôvodný text.'; + return text; // Fallback to original text on error + } +} + // Function to check if video exists (for local testing) async function videoExists(src) { return new Promise(resolve => { @@ -143,6 +165,10 @@ if (currentTranslationMode === 'letters') { translateBtn.addEventListener('click', async () => { autoPlayEnabled = true; + // Lematizácia vstupu + const lemmatizedText = await lemmatizeText(inputText.value); + inputText.value = lemmatizedText; // Update input field with lemmatized text + // Load the video sequence based on the current translation mode if (currentTranslationMode === 'words') { await loadVideoSequenceByWords();