// Writing Analyzer — AI/ML showcase. Analyzes IELTS essays in real-time // using client-side NLP. Shows lexical diversity, grammatical complexity, // coherence scoring, and a predicted band with radar chart. function WritingAnalyzer({ state, update }) { const [text, setText] = useState(''); const [prompt, setPrompt] = useState('Some people believe that university education should be free for everyone. To what extent do you agree or disagree?'); const [taskType, setTaskType] = useState(2); const [analysis, setAnalysis] = useState(null); const [showPrompts, setShowPrompts] = useState(false); const minWords = taskType === 1 ? 150 : 250; const wordCount = text.trim().split(/\s+/).filter(Boolean).length; // Debounced analysis: runs 600ms after user stops typing useEffect(() => { if (wordCount < 30) { setAnalysis(null); return; } const timer = setTimeout(() => { const result = window.nlpAnalyzer.analyze(text, { minWords, prompt }); setAnalysis(result); }, 600); return () => clearTimeout(timer); }, [text, minWords, prompt, wordCount]); // Also get AI feedback from backend (if available) const [aiFeedback, setAiFeedback] = useState(null); const [aiLoading, setAiLoading] = useState(false); const getAIFeedback = async () => { if (!window.apiClient.isConfigured() || !state.auth?.user) return; setAiLoading(true); try { const fb = await window.apiClient.ai.writingScore(taskType, state.profile?.examType || 'academic', prompt, text); setAiFeedback(fb); } catch (e) { console.warn('AI feedback failed:', e.message); } setAiLoading(false); }; const [genLoading, setGenLoading] = useState(false); const randomPrompt = () => { const pool = samplePrompts.filter(p => p.task === taskType); const list = pool.length ? pool : samplePrompts; let pick = list[Math.floor(Math.random() * list.length)]; let guard = 0; while (list.length > 1 && pick.text === prompt && guard++ < 6) { pick = list[Math.floor(Math.random() * list.length)]; } setPrompt(pick.text); setTaskType(pick.task); }; const aiPrompt = async () => { if (!window.apiClient.isConfigured() || !state.auth?.user) { randomPrompt(); return; } setGenLoading(true); try { const res = await window.apiClient.call('/api/ai/writing-prompt', { method: 'POST', body: { task: taskType, examType: state.profile?.examType || 'academic' }, }); const data = res.data || res; if (data && data.prompt) { setPrompt(data.prompt); if (data.task) setTaskType(data.task); } else { randomPrompt(); } } catch (e) { randomPrompt(); } setGenLoading(false); }; const samplePrompts = [ { task: 2, text: 'Some people believe that university education should be free for everyone. To what extent do you agree or disagree?' }, { task: 2, text: 'Nowadays, many people choose to live or work in other countries. What are the advantages and disadvantages of this trend?' }, { task: 2, text: 'Some people think that the increasing use of technology in the workplace is a positive development. Others disagree. Discuss both views and give your opinion.' }, { task: 2, text: 'In many countries, the gap between the rich and the poor is widening. What problems does this cause and what solutions can you suggest?' }, { task: 2, text: 'Some people think children should begin formal education at a very early age. Others believe they should not start school until they are at least seven. Discuss both views and give your opinion.' }, { task: 2, text: 'Many people believe that social media has a negative effect on society. To what extent do you agree or disagree?' }, { task: 2, text: 'In some countries, the average weight of people is increasing and their levels of health and fitness are decreasing. What do you think are the causes of these problems and what measures could be taken to solve them?' }, { task: 2, text: 'Some people believe that governments should spend money on public services rather than on art and culture. To what extent do you agree or disagree?' }, { task: 2, text: 'It is sometimes argued that prison is the best way to deal with crime. Others, however, believe there are better alternatives. Discuss both views and give your own opinion.' }, { task: 2, text: 'Many young people today leave their home country to work abroad. What are the reasons for this, and is it a positive or negative development?' }, { task: 2, text: 'Some people think that the best way to reduce traffic congestion is to provide free public transport. To what extent do you agree or disagree?' }, { task: 2, text: 'Working from home has become increasingly common. Do the advantages of this trend outweigh the disadvantages?' }, { task: 2, text: 'Some believe that environmental problems are too big for individuals to solve, while others think individual action is essential. Discuss both views and give your opinion.' }, { task: 2, text: 'Tourism brings both benefits and problems to a country. Do you think the benefits outweigh the drawbacks?' }, { task: 2, text: 'Some people think that students should study the subjects they choose, while others believe schools should require core subjects. Discuss both views and give your opinion.' }, { task: 2, text: 'Advertising influences what people buy and how they think. Is this a positive or negative development?' }, { task: 1, text: 'The chart below shows the percentage of adults who used the internet in four countries between 2000 and 2020. Summarise the information by selecting and reporting the main features, and make comparisons where relevant.' }, { task: 1, text: 'The graph below shows the population of three cities from 1990 to 2020. Summarise the information by selecting and reporting the main features, and make comparisons where relevant.' }, { task: 1, text: 'The table below shows the average monthly expenditure of households on food, housing, and transport in three countries. Summarise the information by selecting and reporting the main features.' }, { task: 1, text: 'The diagram below shows the process by which recycled paper is produced. Summarise the information by describing the main stages of the process.' }, { task: 1, text: 'The two maps below show a town centre in 1995 and the same town centre today. Summarise the information by selecting and reporting the main features, and make comparisons where relevant.' }, { task: 1, text: 'The bar chart below shows the number of international students enrolled at universities in four countries in 2010 and 2020. Summarise the information and make comparisons where relevant.' }, ]; return (
Client-side NLP scores your writing on all 4 IELTS criteria as you type. No API call needed — runs in your browser.