mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
Created the grammar correction System, and created a helper function to assist with it
This commit is contained in:
parent
d07a961de1
commit
0272a3821d
@ -1,55 +1,55 @@
|
||||
2a60927148abd1d33b818b535e306557
|
||||
::res://::1683484364
|
||||
default_env.tres::Environment::-1::1680461469::0::1::::<><>::
|
||||
icon.png::CompressedTexture2D::1663579034843721578::1659896126::1681665020::1::::<><>::
|
||||
README.txt::TextFile::-1::1679251181::0::1::::<><>::
|
||||
::res://addons/::1679857270
|
||||
::res://addons/godot-sqlite/::1681665058
|
||||
gdsqlite.gdextension::GDExtension::-1::1681665058::0::1::::<><>::
|
||||
godot-sqlite-wrapper.gd::GDScript::-1::1679857271::0::1::::SQLiteWrapper<>RefCounted<>::
|
||||
godot-sqlite.gd::GDScript::-1::1679857271::0::1::::<>RefCounted<>::
|
||||
LICENSE.md::TextFile::-1::1679857270::0::1::::<><>::
|
||||
plugin.cfg::TextFile::-1::1679857271::0::1::::<><>::
|
||||
::res://addons/godot-sqlite/bin/::1681665058
|
||||
::res://addons/godot-sqlite/bin/android/::1679857270
|
||||
::res://addons/godot-sqlite/bin/android/arm64-v8a/::1679857270
|
||||
::res://addons/godot-sqlite/bin/android/armeabi-v7a/::1679857270
|
||||
::res://addons/godot-sqlite/bin/android/x86/::1679857270
|
||||
::res://addons/godot-sqlite/bin/android/x86_64/::1679857270
|
||||
::res://addons/godot-sqlite/bin/ios/::1679857271
|
||||
::res://addons/godot-sqlite/bin/ios/arm64/::1679857270
|
||||
::res://addons/godot-sqlite/bin/ios/armv7/::1679857271
|
||||
::res://addons/godot-sqlite/bin/javascript/::1679857271
|
||||
::res://addons/godot-sqlite/bin/libgdsqlite.macos.template_debug.framework/::1681665058
|
||||
::res://addons/godot-sqlite/bin/libgdsqlite.macos.template_release.framework/::1681665058
|
||||
::res://addons/godot-sqlite/bin/osx/::1679857271
|
||||
::res://addons/godot-sqlite/bin/win64/::1679857271
|
||||
::res://addons/godot-sqlite/bin/x11/::1679857271
|
||||
::res://assets/::1679252065
|
||||
::res://assets/fonts/::1679252065
|
||||
liberation_serif.tres::FontFile::-1::1679252065::0::1::::<><>::res://assets/Fonts_source/LiberationSerif-Regular.ttf
|
||||
liberation_serif_20pt.tres::FontFile::-1::1679252065::0::1::::<><>::res://assets/Fonts_source/LiberationSerif-Regular.ttf
|
||||
liberation_serif_30pt.tres::FontFile::-1::1679252065::0::1::::<><>::res://assets/Fonts_source/LiberationSerif-Regular.ttf
|
||||
liberation_serif_40pt.tres::FontFile::-1::1679252065::0::1::::<><>::res://assets/Fonts_source/LiberationSerif-Regular.ttf
|
||||
::res://assets/fonts/Fonts_source/::1681665020
|
||||
LiberationSerif-Bold.ttf::FontFile::3428046290919973558::1679252065::1681665020::1::::<><>::
|
||||
LiberationSerif-BoldItalic.ttf::FontFile::6973589459942031632::1679252065::1681665020::1::::<><>::
|
||||
LiberationSerif-Italic.ttf::FontFile::3429051925918376143::1679252065::1681665020::1::::<><>::
|
||||
LiberationSerif-Regular.ttf::FontFile::3437532725077625275::1679252065::1681665020::1::::<><>::
|
||||
::res://CharacterCreator/::1659895857
|
||||
::res://databases/::1683481029
|
||||
::res://Dialog/::1683481029
|
||||
dialog_system.gd::GDScript::-1::1683481028::0::1::::<>Node<>::
|
||||
TestDialog.tscn::PackedScene::4730621496714883874::1683481029::0::1::::<><>::res://Dialog/dialog_system.gd
|
||||
::res://GenresSubstitution/::1683481028
|
||||
genre_sub.gd::GDScript::-1::1682880384::0::1::::<>Node<>::
|
||||
TestDB.tscn::PackedScene::3353206590719512815::1683481028::0::1::::<><>::res://GenresSubstitution/genre_sub.gd
|
||||
::res://GenresSubstitution/globalScripts/::1679252065
|
||||
DiceRoller.gd::GDScript::-1::1679252065::0::1::::<>Control<>::
|
||||
::res://Grammar/::1659895937
|
||||
::res://RiskFactors/::1659895947
|
||||
::res://screens/::1683481028
|
||||
MainMenu.tscn::PackedScene::8771866178020998753::1683481028::0::1::::<><>::
|
||||
::res://userInterface/::1679252065
|
||||
But_ChangeScene.gd::GDScript::-1::1679252065::0::1::::<>RefCounted<>::
|
||||
But_ChangeScene.tscn::PackedScene::-1::1679252065::0::1::::<><>::res://UserInterface/But_ChangeScene.gd
|
||||
::res://::1685898397
|
||||
default_env.tres::Environment::-1::1685898240::0::1::::<><>::
|
||||
icon.png::CompressedTexture2D::1663579034843721578::1685898240::1685898240::1::::<><>::
|
||||
README.txt::TextFile::-1::1685898239::0::1::::<><>::
|
||||
::res://addons/::1685898239
|
||||
::res://addons/godot-sqlite/::1685898240
|
||||
gdsqlite.gdextension::GDExtension::-1::1685898240::0::1::::<><>::
|
||||
godot-sqlite-wrapper.gd::GDScript::-1::1685898240::0::1::::SQLiteWrapper<>RefCounted<>::
|
||||
godot-sqlite.gd::GDScript::-1::1685898240::0::1::::<>RefCounted<>::
|
||||
LICENSE.md::TextFile::-1::1685898239::0::1::::<><>::
|
||||
plugin.cfg::TextFile::-1::1685898240::0::1::::<><>::
|
||||
::res://addons/godot-sqlite/bin/::1685898239
|
||||
::res://addons/godot-sqlite/bin/android/::1685898239
|
||||
::res://addons/godot-sqlite/bin/android/arm64-v8a/::1685898239
|
||||
::res://addons/godot-sqlite/bin/android/armeabi-v7a/::1685898239
|
||||
::res://addons/godot-sqlite/bin/android/x86/::1685898239
|
||||
::res://addons/godot-sqlite/bin/android/x86_64/::1685898239
|
||||
::res://addons/godot-sqlite/bin/ios/::1685898239
|
||||
::res://addons/godot-sqlite/bin/ios/arm64/::1685898239
|
||||
::res://addons/godot-sqlite/bin/ios/armv7/::1685898239
|
||||
::res://addons/godot-sqlite/bin/javascript/::1685898239
|
||||
::res://addons/godot-sqlite/bin/libgdsqlite.macos.template_debug.framework/::1685898239
|
||||
::res://addons/godot-sqlite/bin/libgdsqlite.macos.template_release.framework/::1685898239
|
||||
::res://addons/godot-sqlite/bin/osx/::1685898239
|
||||
::res://addons/godot-sqlite/bin/win64/::1685898239
|
||||
::res://addons/godot-sqlite/bin/x11/::1685898239
|
||||
::res://assets/::1685898240
|
||||
::res://assets/fonts/::1685898240
|
||||
liberation_serif.tres::FontFile::-1::1685898240::0::1::::<><>::res://assets/Fonts_source/LiberationSerif-Regular.ttf
|
||||
liberation_serif_20pt.tres::FontFile::-1::1685898240::0::1::::<><>::res://assets/Fonts_source/LiberationSerif-Regular.ttf
|
||||
liberation_serif_30pt.tres::FontFile::-1::1685898240::0::1::::<><>::res://assets/Fonts_source/LiberationSerif-Regular.ttf
|
||||
liberation_serif_40pt.tres::FontFile::-1::1685898240::0::1::::<><>::res://assets/Fonts_source/LiberationSerif-Regular.ttf
|
||||
::res://assets/fonts/Fonts_source/::1685898240
|
||||
LiberationSerif-Bold.ttf::FontFile::3428046290919973558::1685898240::1685898240::1::::<><>::
|
||||
LiberationSerif-BoldItalic.ttf::FontFile::6973589459942031632::1685898240::1685898240::1::::<><>::
|
||||
LiberationSerif-Italic.ttf::FontFile::3429051925918376143::1685898240::1685898240::1::::<><>::
|
||||
LiberationSerif-Regular.ttf::FontFile::3437532725077625275::1685898240::1685898240::1::::<><>::
|
||||
::res://databases/::1685898240
|
||||
::res://Dialog/::1685898239
|
||||
dialog_system.gd::GDScript::-1::1685898239::0::1::::<>Node<>::
|
||||
TestDialog.tscn::PackedScene::4730621496714883874::1685898239::0::1::::<><>::res://Dialog/dialog_system.gd
|
||||
::res://GenresSubstitution/::1685898239
|
||||
genre_sub.gd::GDScript::-1::1685898239::0::1::::<>Node<>::
|
||||
TestDB.tscn::PackedScene::3353206590719512815::1685898239::0::1::::<><>::res://GenresSubstitution/genre_sub.gd
|
||||
::res://GenresSubstitution/globalScripts/::1685898239
|
||||
DiceRoller.gd::GDScript::-1::1685898239::0::1::::<>Control<>::
|
||||
::res://Grammar/::1685898239
|
||||
GrammarTest.gd::GDScript::-1::1685898239::0::1::::<>Node2D<>::
|
||||
GrammarTest.tscn::PackedScene::3628749051665588560::1685898239::0::1::::<><>::res://Grammar/GrammarTest.gd
|
||||
::res://screens/::1685898240
|
||||
MainMenu.tscn::PackedScene::8771866178020998753::1685898240::0::1::::<><>::
|
||||
::res://userInterface/::1685898240
|
||||
But_ChangeScene.gd::GDScript::-1::1685898240::0::1::::<>RefCounted<>::
|
||||
But_ChangeScene.tscn::PackedScene::-1::1685898240::0::1::::<><>::res://UserInterface/But_ChangeScene.gd
|
||||
|
@ -9,7 +9,7 @@ run_reload_scripts=true
|
||||
|
||||
[recent_files]
|
||||
|
||||
scenes=["res://Dialog/TestDialog.tscn", "res://GenresSubstitution/TestDB.tscn", "res://screens/MainMenu.tscn"]
|
||||
scenes=["res://Grammar/GrammarTest.tscn", "res://Dialog/TestDialog.tscn", "res://GenresSubstitution/TestDB.tscn", "res://screens/MainMenu.tscn"]
|
||||
scripts=["res://Grammar/GrammarTest.gd", "res://Dialog/dialog_system.gd", "res://GenresSubstitution/genre_sub.gd"]
|
||||
|
||||
[script_setup]
|
||||
|
@ -17,11 +17,11 @@ state={
|
||||
state={
|
||||
"bookmarks": PackedInt32Array(),
|
||||
"breakpoints": PackedInt32Array(),
|
||||
"column": 45,
|
||||
"column": 51,
|
||||
"folded_lines": Array[int]([]),
|
||||
"h_scroll_position": 114,
|
||||
"row": 101,
|
||||
"scroll_position": 66.0,
|
||||
"h_scroll_position": 117,
|
||||
"row": 77,
|
||||
"scroll_position": 49.0,
|
||||
"selection": false,
|
||||
"syntax_highlighter": "GDScript"
|
||||
}
|
||||
@ -31,11 +31,11 @@ state={
|
||||
state={
|
||||
"bookmarks": PackedInt32Array(),
|
||||
"breakpoints": PackedInt32Array(),
|
||||
"column": 1,
|
||||
"column": 28,
|
||||
"folded_lines": Array[int]([]),
|
||||
"h_scroll_position": 0,
|
||||
"row": 42,
|
||||
"scroll_position": 16.0,
|
||||
"row": 46,
|
||||
"scroll_position": 21.0,
|
||||
"selection": false,
|
||||
"syntax_highlighter": "GDScript"
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,43 +1,83 @@
|
||||
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()
|
||||
#rebuild_sentence is here to assist with making a human readable sentence, out of the array created in correct_sentence.
|
||||
#Example of how to call this function from within another function:
|
||||
#
|
||||
#var outputString = rebuild_sentence(newWords)
|
||||
#
|
||||
# return(outputString)
|
||||
|
||||
func rebuild_sentence(input_sentance: Array) -> String:
|
||||
var outputString = ""
|
||||
for i in range(input_sentance.size()):
|
||||
outputString += input_sentance[i] + " "
|
||||
|
||||
return outputString
|
||||
|
||||
|
||||
#correct_sentances will output a modified string array, based on the sentance String that you input.
|
||||
#
|
||||
#Here is what is outputed from the following function calls.
|
||||
#
|
||||
# print(correct_sentence("An unicorn is an mythical creature"))
|
||||
# print(correct_sentence("A apple a day keeps an doctor away"))
|
||||
# print(correct_sentence("An hour"))
|
||||
# print(correct_sentence("Eating seeds as an passtime activity..."))
|
||||
# print(correct_sentence("Wake Up... Grab an brush and put on a little makeup..."))
|
||||
#
|
||||
# ["A", "unicorn", "is", "a", "mythical", "creature"]
|
||||
# ["A", "apple", "a", "day", "keeps", "a", "doctor", "away"]
|
||||
# ["An", "hour"]
|
||||
# ["Eating", "seeds", "as", "a", "passtime", "activity..."]
|
||||
# ["Wake", "Up...", "Grab", "a", "brush", "and", "put", "on", "a", "little", "makeup..."]
|
||||
|
||||
|
||||
func correct_sentence(input_string: String) -> String:
|
||||
var words = input_string.split(" ")
|
||||
var newWords = words
|
||||
var articleList = ["a", "an", "A", "An"]
|
||||
var exceptionsListForAn = ""
|
||||
var exceptionsListForA = ""
|
||||
var exceptionsList = ["hour"]
|
||||
|
||||
# One Potential Addition, could be that we make an exception list for words that should be prefixed with A, and another one for words that should be prefixed with An
|
||||
|
||||
# Start Filtering the words
|
||||
for i in range(words.size()):
|
||||
var current_word = words[i]
|
||||
var first_character = current_word.substr(0, 1).to_lower()
|
||||
|
||||
# Correct Every Word after the first word.
|
||||
if i > 1:
|
||||
var last_word = words[i-1]
|
||||
|
||||
if current_word != last_word:
|
||||
if articleList.has(last_word):
|
||||
if first_character.match("[aeiouAEIOU]") or exceptionsList.has(last_word):
|
||||
newWords[i-1] = "an"
|
||||
else:
|
||||
newWords[i-1] = "a"
|
||||
|
||||
# Correcting the first word of the string now.
|
||||
if words[0] != words[1]:
|
||||
if articleList.has(words[0]):
|
||||
var nextWordFirstChar = words[1].substr(0, 1).to_lower()
|
||||
if nextWordFirstChar.match("[aeiouAEIOU]") or exceptionsList.has(words[1]):
|
||||
newWords[0] = "An"
|
||||
else:
|
||||
newWords[0] = "A"
|
||||
|
||||
var outputString = rebuild_sentence(newWords)
|
||||
|
||||
return(outputString)
|
||||
|
||||
|
||||
func _ready():
|
||||
print(correct_sentence("Eating seeds as an passtime activity..."))
|
||||
|
Loading…
Reference in New Issue
Block a user