Started work on the new Grammar checker system.

This commit is contained in:
PersonGuyGit
2023-05-07 13:08:15 -06:00
parent a055f6359d
commit daac13b923
11 changed files with 258 additions and 16 deletions

View File

@ -0,0 +1,43 @@
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready():
print(checkAndCorrectGrammar("A unicorn is a mythical creature"))
print(checkAndCorrectGrammar("An apple a day keeps the doctor away"))
print(checkAndCorrectGrammar("An house on the hill."))
print(checkAndCorrectGrammar("A egg a day is unhealthy."))
print(checkAndCorrectGrammar("An unique idea."))
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func checkAndCorrectGrammar(str: String) -> String:
var vowels: Array = ["a", "e", "i", "o", "u"]
var words: Array = str.split(" ")
var correctedStr: String = ""
for word in words:
var firstChar: String = word[0].to_lower()
if firstChar in vowels:
if word.substr(0, 2).to_lower() != "an":
word = "an " + word
print("Changed \"" + word + "\" to \"" + "an " + word + "\"")
else:
print("Kept \"" + word + "\"")
correctedStr += word + " "
else:
if word.substr(0, 1).to_lower() != "a":
if word.substr(1, 1) == "n":
word = word.substr(2, word.length())
print("Changed \"" + word + "\" to \"" + "a " + word + "\"")
else:
word = "a " + word
print("Changed \"" + word + "\" to \"" + "a " + word + "\"")
else:
print("Kept \"" + word + "\"")
correctedStr += word + " "
return correctedStr.strip_edges()

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://brx174ry2iceq"]
[ext_resource type="Script" path="res://Grammar/GrammarTest.gd" id="1_kk72l"]
[node name="GrammarTest" type="Node2D"]
script = ExtResource("1_kk72l")