Week 8: Text
Write a program that allows the user to enter a sentence which the computer will then spell check.
Hint: Use the Dictionary class to look up the definition of each word.
If no definition exists then it can be assumed the word is spelt incorrectly.Example:
INPUT: The kwick brown fox jumps over a lazey dog.
OUTPUT: “kwick” and “lazey” are not correct.
Scrivi un programma per controllare la correttezza ortografica di una frase inserita dall’utente.
Suggerimento: utilizza la libreria Dictionary per controllare la definizione di ciascuna parola.
Se non esiste una definizione allora si può concludere che la parola sia stata scritta in modo scorretto.
Soluzione
TextWindow.Write("Inserisci un testo in inglese: ")
testo=TextWindow.Read()
'------------------------------------------------------------
'------------------------------------------------------------
ELENCO="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
parole=0
IN_PAROLA=0
parola=""
For i=1 To Text.GetLength(testo)
car=Text.GetSubText(testo,i,1)
If Text.IsSubText(ELENCO,car) Then
IN_PAROLA=1
parola=parola+car
Else
If IN_PAROLA=1 Then
IN_PAROLA=0
GestisciParola()
parola=""
EndIf
EndIf
EndFor
'------------------------------------------------------------
If IN_PAROLA=1 Then
GestisciParola()
EndIf
'------------------------------------------------------------
if parole=0 Then
TextWindow.WriteLine("The sentence is correct.")
ElseIf parole=1 Then
TextWindow.WriteLine(" is not correct.")
Else
TextWindow.WriteLine(" are not correct.")
endif
'------------------------------------------------------------
'------------------------------------------------------------
Sub GestisciParola
risposta=Dictionary.GetDefinition(parola)
If Text.GetLength(risposta)=0 Then
If parole > 0 then
TextWindow.Write(" and ")
endif
TextWindow.Write("'" + parola + "'")
parole=parole+1
EndIf
EndSub