/* PROGRAM ACCENT This program will parse Spanish words in syllables, it will determine if an accent is needed and it will explain how the decision was made based on the accent placement rules. I've coded the accent rules and most of the exceptions in simple routines for the sake of portability so don't look for snazzy effects. A brief explanation of the rules can be found in the <instruction> function. */ #define MAXCHAR 50 /*maximum letters in a word*/ #define MAXSYL 10 /*maximum number of syllables in a word*/ #define SYLSIZE 5 /*maximum letters in a syllable*/ #define TRUE 1 #define FALSE 0 #define UP_LOW 'a'-'A' #include <ctype.h> #include <stdio.h> void main() { char word[MAXCHAR]; instructions(); strcpy(word,"xxx"); while (strlen(word) !=0) { printf("Enter a word or <CR> to end the program > "); gets(word); if (strlen(word)==0) { printf("\nGood bye and thank you for using the accent finder.\n"); break; } if (invalidword(word)==TRUE) printf("Sorry.. bad input!!\n"); else { lowercase(word); printf("The word you entered is <%s>\n",word); switch (strlen(word)) { case 1: printf("Monosunds do not have accents.\n"); break; case 2: if (strcmp(word,"mi")==0) mimsg(); else if (strcmp(word,"si")==0) simsg(); else if (strcmp(word,"el")==0) elmsg(); else printf("The should be no accent.\n"); break; case 3: printf("Monovowels have different rules (I.E. ma/s.\n"); process(word); break; default: printf("This is the word parsed in syllables:\n"); process(word); break; } } } } instructions() { printf("\n\ Welcome to the accent finder\n\ Enter the words in upper or lower case WITHOUT accents\n\ or punctuation. The program will represent accents with a slash /.\n\n\ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\ This is the accent rule: Words are rated with + or - on two criteria:\n\ 1) What is the last sound of the word:\n\ If a word ends with an N, S or a vowel the word gets a '+'\n\ else the word gets a minus '-.'\n\ 2) Is the emphasis on the penultimate syllable (next to last):\n\ If yes the the word gets a '+'; else a '-.'\n\ If the word yields a + - or - + combination on these two criteria\n\ then an accent is placed on the vowel of the emphasis syllable.\n\ Ex: fran-ces (emphasis on <ces>) and fran-ce-sa (emphasis on <ce>\n\ will yield an accent on france/s but not on francesa.\n\n\ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\ All interrogative prepositions get an accent when used in a question!\n\ Ex: ?Que/ dice?\n\ An accent is also required if the emphasis is on the WEAK vowel of a diphthong\n\ Ex: Estanteri/a\n\n"); } /*shift a word to lower case*/ lowercase(word) char word[]; { int i; for (i=0;i<=strlen(word)-1;i++) if (isupper(word[i])!=FALSE) word[i]+=UP_LOW; } /*determines bad input*/ int invalidword(word) char word[]; { int i,badword=FALSE; for (i=0;i<=strlen(word)-1;i++) { if (isalpha(word[i])==FALSE) { badword=TRUE; break; } } return(badword); } /* message in case the word is mi*/ mimsg () { printf("MI does not take an accent when used as a possesive pronoun but\n"); printf("it has one when used as a reflexive pronoun.\n"); printf("Ex: Mi perro es feo.\nMe afeito a mi/ mismo.\n"); } /* message in case the word is si*/ simsg () { printf("SI has an accent when used as 'yes' or a reflexive pronoun\n"); printf("Ex: !Si/, me duelen los dientes!\nSe afeita a si/ mismo.\n"); } /* message in case the word is el*/ elmsg () { printf("EL has an accent when used as a pronoun and not as an article\n"); printf("Ex: E'l me dio un puno.\n!Deme el dinero!"); } /* what to do with all other words*/ process (word) char word[]; { char TempString[MAXCHAR]; int vowel[MAXCHAR], strong[MAXCHAR], boundary[MAXCHAR], EndPlus, CountPlus, LastSyl, StressSyl, StressLet, length; char syllables[MAXSYL] [SYLSIZE]; length=strlen(word)-1; initialize(word,strong,boundary,vowel,syllables); set_quality(word,strong,vowel,length); set_sylls(word,boundary,vowel,strong,length); split_consonants(boundary,vowel,length); weld_ch(word,boundary,length); weld_liquids(word,boundary,vowel,length); if (vowel[length]==FALSE) boundary[length]=FALSE; divide(boundary,word,syllables,length); LastSyl=eval_sylls(syllables); StressSyl=check_syl(LastSyl); StressLet= set_stress(length,StressSyl,vowel,boundary); EndPlus=CountPlus=FALSE; if (vowel[length]==TRUE || vowel[length-1]==TRUE) if (vowel[length]==TRUE || is_N_S(word[length])==TRUE) EndPlus=TRUE; if (LastSyl-StressSyl==1) CountPlus=TRUE; if (EndPlus!=CountPlus || (strong[StressLet-1]==TRUE && strong[StressLet]==FALSE) || (strong[length-1]==FALSE && vowel[length-1]==TRUE && strong[length]==TRUE)) display_accent(word,StressLet,length); else printf("No accent!\n"); infomsg(word,EndPlus,CountPlus,length); } /* is this a vowel */ is_vowel(character) char character; { if (character=='a' || character=='e' || character=='i' || character=='o' || character=='u') return(TRUE); else return(FALSE); } /* is this a string vowel */ is_strong(character) char character; { if (character=='a' || character=='e' || character=='o') return(TRUE); else return(FALSE); } /* is this a liquid */ is_liquid(character) char character; { if (character=='l' || character=='r') return(TRUE); else return(FALSE); } /* is it an n or an s */ is_N_S(character) char character; { if (character=='n' || character=='s') return(TRUE); else return(FALSE); } initialize(word,strong,boundary,vowel,syllables) char word[]; int strong[], boundary[], vowel[]; char syllables[MAXSYL] [SYLSIZE]; { int i; for (i=0;i<=MAXCHAR-1;i++) { boundary[i]=FALSE; vowel[i]=FALSE; strong[i]=FALSE; }; boundary[strlen(word)]=TRUE; for (i=0;i<=MAXSYL-1;strncpy(syllables[i++],"",SYLSIZE-1)); } set_quality(word,strong,vowel,length) char word[]; int strong[], vowel[], length; { int i; for (i=0;i<=length;i++) if (is_vowel(word[i])) { vowel[i]=TRUE; if (is_strong(word[i])) strong[i]=TRUE; } } /* parse syllables. */ set_sylls(word,boundary,vowel,strong,length) char word[]; int boundary[], vowel[], strong[], length; { int i; for (i=1;i<=length;i++) { if ((vowel[i]==FALSE && vowel[i-1]) || (word[i-1]=='n' && word[i]=='t') || (strong[i-1] && strong[i]==FALSE) || (strong[i-1] && strong[i]) || (strong[i] && ~strong[i-1] && vowel[i-1])) boundary[i]=TRUE; if (i>1) { if (vowel[i-2] && vowel[i-1]==FALSE && vowel[i]==FALSE && word[i]==word[i-1]) { boundary[i-1]=TRUE; boundary[i]=FALSE; } } } } /* split syllables between certain consonants */ split_consonants(boundary,vowel,length) int boundary[], vowel[], length; { int i; for (i=2;i<=length;i++) if (vowel[i-2] && vowel[i-1]==FALSE && vowel[i]==FALSE) { boundary[i-1]=FALSE; boundary[i]=TRUE; }; } /* c and h belong in the same syllable */ weld_ch(word,boundary,length) char word[]; int boundary[], length; { int i; for (i=2;i<=length;i++) if (word[i-1]=='c' && boundary[i-1]==FALSE && word[i]=='h' && boundary[i]) { boundary[i-1]=TRUE; boundary[i]=FALSE; }; } /* liquids belong in the same syllable */ weld_liquids(word,boundary,vowel,length) char word[]; int boundary[], vowel[], length; { int i; for (i=2;i<=length;i++) if (vowel[i-2] && vowel[i-1]==FALSE && vowel[i]==FALSE && is_liquid(word[i])) { boundary[i-1]=TRUE; boundary[i]=FALSE; }; } divide(boundary,word,syllables,length) int boundary[], length; char word[], syllables[MAXSYL] [SYLSIZE]; { char temp[1]; int i=0,j=1; strcpy(temp,""); strncpy(syllables[i],word,1); while (j<=length) { strncpy(temp,word+j,1); if (boundary[j]==FALSE) strncat(syllables[i],temp,1); else { strncpy(syllables[i+1],temp,1); i++; } j++; } } int eval_sylls(syllables) char syllables[MAXSYL] [SYLSIZE]; { int i=0; while (strcmp(syllables[i],"") != 0) { printf("# %d <%s> ",i+1,syllables[i]); i++; } printf("\n"); return(i-1); } int check_syl(LastSyl) int LastSyl; { int StressSyl; char temp[2]; printf("Enter the number of the emphasis syllable (1 to %d) > ",LastSyl+1); gets(temp); StressSyl=atoi(temp); StressSyl--; while (StressSyl<0 || StressSyl>LastSyl) { printf("Invalid syllable number\n"); printf("Enter the syllable number > "); gets(temp); StressSyl=atoi(temp); StressSyl--; } return(StressSyl); } int set_stress(length,StressSyl,vowel,boundary) int length,StressSyl,vowel[],boundary[]; { int i,count,temp; count=0; for (i=0;i<=length;i++) { if (boundary[i]==TRUE) count++; if (count==StressSyl && vowel[i]==TRUE) temp=i; } return(temp); } display_accent(word,StressLet,length) char word[]; int StressLet,length; {int i; printf("The word %s has a written accent\n",word); for (i=0;i<=length;i++){ printf(" %c",word[i]); if (i==StressLet) printf("/"); else printf(" "); } printf("\n"); } infomsg(word,EndPlus,CountPlus,length) char word[]; int EndPlus, CountPlus,length; { printf("The final letter of <%s> is <%c> thus the 'Word End' is",word,word[length]); if (EndPlus==TRUE) printf("'+'\n"); else printf("'-'\n"); printf("The sign for emphasis placement is "); if (CountPlus==TRUE) printf("'+' (penultimate syllable)\n"); else printf("'-' (not the penultimate syllable.)\n"); printf("A written accent is required only when the signs are different .\n"); }