Swahili Grammar Analysis Tool

Swahili Grammar Analysis Tool

Swahili Noun Class Identifier

Enter a noun above to see its class and agreement examples.

Brief Overview of Swahili Noun Classes:

M-WA (Class 1/2): People. Singular prefix 'm-', plural 'wa-'. Ex: mtu (person) - watu (people).

M-MI (Class 3/4): Trees, inanimate objects. Singular prefix 'm-', plural 'mi-'. Ex: mti (tree) - miti (trees).

JI-MA (Class 5/6): Augmentatives, some nouns. Singular prefix 'ji-', plural 'ma-'. Ex: jicho (eye) - macho (eyes).

KI-VI (Class 7/8): Things, diminutives, languages. Singular prefix 'ki-', plural 'vi-'. Ex: kitabu (book) - vitabu (books).

N-N (Class 9/10): Animals, some inanimate. Singular and plural typically 'n-' or 'm-' or no prefix. Ex: nyumba (house) - nyumba (houses).

U-N (Class 11/10): Abstract nouns, long thin objects. No common plural class, or N-N. Ex: ufagio (broom) - fagio (brooms).

U- (Class 11 singular): Abstract nouns with no common plural. Ex: uwizi (theft).

KU- (Class 15): Infinitives (verb nouns). Ex: kusoma (to read).

MA- (Class 6): Plural of Ji-, also mass nouns. Ex: maji (water).

PA- (Class 16 Locative): Definite place. Ex: pamoja (at one place).

KU- (Class 17 Locative): Indefinite direction/to. Ex: kule (there/to there).

MU- (Class 18 Locative): Inside/in. Ex: mtoni (in the river).

Swahili Verb Structure Analyzer

Enter a verb above to see its components.

Common Swahili Phrases with Basic Grammar Notes

Habari? - How are you? (Lit: News?)
Grammar: Informal greeting, common response "Nzuri" (Good).

Jina langu ni... - My name is...
Grammar: "Jina" (name - JI-MA class), "langu" (my - agrees with JI-MA), "ni" (is).

Unaongea Kiingereza? - Do you speak English?
Grammar: "U-" (you - singular subject prefix), "-na-" (present tense marker), "-ongea" (speak - verb root), "Kiingereza" (English - KI-VI class language prefix).

Nataka maji. - I want water.
Grammar: "N-" (I - subject prefix), "-a-" (present indefinite/habitual tense marker), "-taka" (want - verb root), "maji" (water - MA- class, mass noun).

Ninaenda sokoni. - I am going to the market.
Grammar: "Ni-" (I - subject prefix), "-na-" (present continuous tense marker), "-enda" (go - verb root), "sokoni" (to the market - locative '-ni' suffix).

Samahani. - Excuse me / Sorry.
Grammar: A common interjection, derived from the verb "kusamehe" (to forgive).

Asante sana. - Thank you very much.
Grammar: "Asante" (thank you), "sana" (very much).

This might be an Imperative or a verb starting directly with its root.

`; } } // Step 2: Identify Tense Marker (Longest first) let foundTense = false; const sortedTenseMarkers = Object.keys(tenseMarkers).sort((a, b) => b.length - a.length); for (const tense of sortedTenseMarkers) { if (tempVerb.startsWith(tense)) { tenseMarker = tense; analysis += `

Tense/Aspect Marker: ${tenseMarker} (${tenseMarkers[tense]})

`; tempVerb = tempVerb.substring(tense.length); foundTense = true; break; } } if (!foundTense && foundSubject) { // Only state implied 'a' if a subject prefix was found analysis += `

Tense/Aspect Marker: Ø (Often implied 'a' for habitual/indefinite present)

`; } // Step 3: Identify Object Infix (optional, Longest first) let foundObjectInfix = false; const sortedObjectInfixes = Object.keys(objectInfixes).sort((a, b) => b.length - a.length); for (const objInfix of sortedObjectInfixes) { if (tempVerb.startsWith(objInfix) && tempVerb.length > objInfix.length) { // Ensure it's a true infix, not just a root start objectInfix = objInfix; analysis += `

Object Infix: ${objectInfix} (refers to ${objectInfixes[objInfix]})

`; tempVerb = tempVerb.substring(objInfix.length); foundObjectInfix = true; break; } } // The remaining part is the verb root + final vowel/suffix verbRoot = tempVerb; // Attempt to identify final suffix and true root if (verbRoot.endsWith('a')) { finalSuffix = 'a (Final Vowel)'; verbRoot = verbRoot.slice(0, -1); // Remove 'a' for a more core root } else if (verbRoot.endsWith('e')) { finalSuffix = 'e (Subjunctive/Passive/Applicative)'; verbRoot = verbRoot.slice(0, -1); } else if (verbRoot.endsWith('i')) { finalSuffix = 'i (Stative/Passive/Reciprocal)'; verbRoot = verbRoot.slice(0, -1); } else if (verbRoot.endsWith('wa')) { finalSuffix = 'wa (Passive)'; verbRoot = verbRoot.slice(0, -2); } else if (verbRoot.endsWith('ana')) { finalSuffix = 'ana (Reciprocal)'; verbRoot = verbRoot.slice(0, -3); } else if (verbRoot.endsWith('isha')) { finalSuffix = 'isha (Causative)'; verbRoot = verbRoot.slice(0, -4); } else if (verbRoot.endsWith('ia')) { finalSuffix = 'ia (Applicative)'; verbRoot = verbRoot.slice(0, -2); } analysis += `

Approximate Verb Root: ${verbRoot || 'N/A'}

`; if (finalSuffix) { analysis += `

Final Suffix: -${finalSuffix}

`; } else if (verbRoot.length > 0) { analysis += `

Final Suffix: N/A (Irregular or Imperative Form)

`; } // Basic common conjugations for known verbs (example) if (verbRoot === 'som') { analysis += `

Examples of '-soma' (to read) conjugation:

`; analysis += `
  • Ninasoma (I am reading)
  • Ulisoma (You read)
  • Atasoma (He/She will read)
  • Wamesoma (They have read)
`; } else if (verbRoot === 'l' && (finalSuffix.includes('a') || verb.endsWith('kula'))) { // 'l' for 'kula' (root is often just 'l' before 'a') analysis += `

Examples of '-la' (to eat) conjugation:

`; analysis += `
  • Nakula (I am eating)
  • Alikula (He/She ate)
  • Tutakula (We will eat)
  • Mmekula (You (pl) have eaten)
`; } verbAnalysisOutput.innerHTML = analysis; } // --- PDF Generation --- function generatePdf() { // IMPORTANT: Ensure jsPDF is loaded before using it. // It's possible Elementor loads external scripts asynchronously. // This check ensures it's available. if (typeof window.jsPDF === 'undefined') { alert("PDF generation library is still loading or failed to load. Please wait a moment and try again. If the issue persists, please check your internet connection or browser console for errors."); console.error("jsPDF is undefined, cannot generate PDF. It likely hasn't finished loading."); return; } const doc = new window.jsPDF(); const margin = 15; let y = margin; const lineHeight = 7; const sectionSpacing = 15; const outputSectionWidth = doc.internal.pageSize.getWidth() - (2 * margin); doc.setFont("helvetica", "normal"); doc.setFontSize(18); doc.setTextColor(44, 62, 80); doc.text("Swahili Grammar Summary", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' }); y += sectionSpacing; // Noun Classes Section doc.setFontSize(14); doc.setTextColor(0, 123, 255); doc.text("I. Swahili Noun Classes", margin, y); y += lineHeight * 1.5; doc.setFontSize(10); doc.setTextColor(0, 0, 0); // Black for general text let tempY = y; const maxLineHeight = 5; // Smaller line height for dense text nounClassesData.forEach(nc => { const classTitle = `${nc.class}:`; const description = `${nc.examples.length > 0 ? 'Ex: ' + nc.examples.join(', ') : ''} ${nc.plural_examples.length > 0 ? 'Plural: ' + nc.plural_examples.join(', ') : ''}`; const wrappedDescription = doc.splitTextToSize(description, outputSectionWidth - 30); // Indent slightly for bullet point // Check for page overflow before adding content if (tempY + lineHeight * 2 + (wrappedDescription.length * maxLineHeight) > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); tempY = margin; doc.setFontSize(10); doc.setTextColor(0, 0, 0); } doc.text(classTitle, margin + 5, tempY); // Indent for readability tempY += lineHeight; wrappedDescription.forEach(line => { doc.text(line, margin + 10, tempY); tempY += maxLineHeight; }); tempY += maxLineHeight; // Add extra space between noun classes }); y = tempY + sectionSpacing; // Update main Y position after noun classes // Verb Analysis Section - General Info doc.setFontSize(14); doc.setTextColor(0, 123, 255); // Check for page overflow if (y + lineHeight * 5 > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); y = margin; } doc.text("II. Swahili Verb Structure", margin, y); y += lineHeight * 1.5; doc.setFontSize(10); doc.setTextColor(0, 0, 0); const verbStructureText = `Swahili verbs are agglutinative, meaning they are built by adding prefixes and suffixes to a verb root. Typical structure: Subject Prefix + Tense/Aspect Marker + (Object Infix) + Verb Root + Final Vowel.`; doc.text(doc.splitTextToSize(verbStructureText, outputSectionWidth), margin, y); y += lineHeight * 3; doc.text("Common Prefixes & Markers:", margin, y); y += lineHeight; doc.text(" - Subject Prefixes (e.g., ni- (I), u- (you), a- (he/she), tu- (we), m- (you-pl), wa- (they))", margin, y); y += lineHeight; doc.text(" - Tense Markers (e.g., -na- (present cont.), -li- (past), -ta- (future), -me- (present perf.))", margin, y); y += lineHeight; doc.text(" - Object Infixes (e.g., -ni- (me), -ku- (you), -wa- (them/you-pl))", margin, y); y += lineHeight; doc.text(" - Infinitive: ku- (e.g., kusoma - to read)", margin, y); y += sectionSpacing; // Common Phrases Section doc.setFontSize(14); doc.setTextColor(0, 123, 255); // Check for page overflow if (y + lineHeight * 2 > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); y = margin; } doc.text("III. Common Swahili Phrases & Grammar Notes", margin, y); y += lineHeight * 1.5; doc.setFontSize(10); doc.setTextColor(0, 0, 0); const phrasesContent = document.getElementById('phrasesOutput').innerText.trim(); const phrasesLines = phrasesContent.split('\n'); phrasesLines.forEach(line => { if (line.trim() === '') return; // Check for new page before adding line // Estimate height based on line breaks and font size const lineLength = doc.getStringUnitWidth(line) * doc.internal.getFontSize(); const numLinesInPdf = Math.ceil(lineLength / outputSectionWidth) || 1; const estimatedHeight = numLinesInPdf * lineHeight + 3; // +3 for spacing if (y + estimatedHeight > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); y = margin; doc.setFontSize(10); doc.setTextColor(0, 0, 0); } doc.text(doc.splitTextToSize(line, outputSectionWidth), margin, y); y += estimatedHeight; }); doc.save('Swahili_Grammar_Summary.pdf'); } // --- Attach Event Listeners --- if (analyzeNounButton) analyzeNounButton.addEventListener('click', analyzeNoun); if (nounInput) { nounInput.addEventListener('keypress', function(e) { if (e.key === 'Enter') { analyzeNoun(); } }); } if (analyzeVerbButton) analyzeVerbButton.addEventListener('click', analyzeVerb); if (verbInput) { verbInput.addEventListener('keypress', function(e) { if (e.key === 'Enter') { analyzeVerb(); } }); } if (downloadPdfButton) downloadPdfButton.addEventListener('click', generatePdf); // Navigation buttons if (prevTabButton) { prevTabButton.addEventListener('click', function() { if (currentTabIndex > 0) { currentTabIndex--; const nextTabId = tabButtons[currentTabIndex].id.replace('tab', '').toLowerCase(); openTab(nextTabId, tabButtons[currentTabIndex]); } }); } if (nextTabButton) { nextTabButton.addEventListener('click', function() { if (currentTabIndex < tabButtons.length - 1) { currentTabIndex++; const nextTabId = tabButtons[currentTabIndex].id.replace('tab', '').toLowerCase(); openTab(nextTabId, tabButtons[currentTabIndex]); } }); } // Initial state update for navigation buttons updateNavigationButtons(); });
Scroll to Top