From 24b1d2c77276b64b0284dffb710372dd64e57868 Mon Sep 17 00:00:00 2001 From: PersonGuyGit Date: Sun, 4 Jun 2023 12:59:28 -0600 Subject: [PATCH] Made some changes to the natural language algorith, to imporve the correction of grammar. It still needs work with H words and the exceptions list related to AN. --- ...lding-71aa8090850efd11588c09ff1805432e.cfg | 3 ++ ...lding-922627201aaf8efd92e730ef115c89b2.cfg | 3 ++ .../.godot/editor/editor_layout.cfg | 4 +- .../.godot/editor/filesystem_cache8 | 22 +++++----- .../.godot/editor/filesystem_update4 | 2 + .../.godot/editor/project_metadata.cfg | 2 +- .../.godot/editor/recent_dirs | 1 + .../.godot/editor/script_editor_cache.cfg | 44 +++++++++++++++---- .../Grammar/ExceptionsForA.json | 3 ++ .../Grammar/ExceptionsForAn.json | 5 +++ .../Grammar/GrammarTest.gd | 37 ++++++++++++---- 11 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/ExceptionsForA.json-folding-71aa8090850efd11588c09ff1805432e.cfg create mode 100644 Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/ExceptionsForAn.json-folding-922627201aaf8efd92e730ef115c89b2.cfg create mode 100644 Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/recent_dirs create mode 100644 Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ExceptionsForA.json create mode 100644 Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ExceptionsForAn.json diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/ExceptionsForA.json-folding-71aa8090850efd11588c09ff1805432e.cfg b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/ExceptionsForA.json-folding-71aa8090850efd11588c09ff1805432e.cfg new file mode 100644 index 0000000..e860dd4 --- /dev/null +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/ExceptionsForA.json-folding-71aa8090850efd11588c09ff1805432e.cfg @@ -0,0 +1,3 @@ +[folding] + +sections_unfolded=PackedStringArray() diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/ExceptionsForAn.json-folding-922627201aaf8efd92e730ef115c89b2.cfg b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/ExceptionsForAn.json-folding-922627201aaf8efd92e730ef115c89b2.cfg new file mode 100644 index 0000000..e860dd4 --- /dev/null +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/ExceptionsForAn.json-folding-922627201aaf8efd92e730ef115c89b2.cfg @@ -0,0 +1,3 @@ +[folding] + +sections_unfolded=PackedStringArray() diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/editor_layout.cfg b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/editor_layout.cfg index 6568a5f..fd7b03e 100644 --- a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/editor_layout.cfg +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/editor_layout.cfg @@ -16,11 +16,11 @@ dock_5="Inspector,Node,History" [EditorNode] -open_scenes=["res://screens/MainMenu.tscn", "res://GenresSubstitution/TestDB.tscn", "res://Dialog/TestDialog.tscn", "res://Grammar/GrammarTest.tscn"] +open_scenes=["res://Grammar/GrammarTest.tscn"] [ScriptEditor] -open_scripts=["res://Dialog/dialog_system.gd", "res://GenresSubstitution/genre_sub.gd", "res://Grammar/GrammarTest.gd"] +open_scripts=["res://Dialog/dialog_system.gd", "res://Grammar/ExceptionsForA.json", "res://Grammar/ExceptionsForAn.json", "res://GenresSubstitution/genre_sub.gd", "res://Grammar/GrammarTest.gd"] open_help=[] script_split_offset=150 list_split_offset=0 diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/filesystem_cache8 b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/filesystem_cache8 index 3fb68f2..4a10d9a 100644 --- a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/filesystem_cache8 +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/filesystem_cache8 @@ -1,5 +1,5 @@ 2a60927148abd1d33b818b535e306557 -::res://::1685898397 +::res://::1685901083 default_env.tres::Environment::-1::1685898240::0::1::::<><>:: icon.png::CompressedTexture2D::1663579034843721578::1685898240::1685898240::1::::<><>:: README.txt::TextFile::-1::1685898239::0::1::::<><>:: @@ -37,19 +37,21 @@ LiberationSerif-BoldItalic.ttf::FontFile::6973589459942031632::1685898240::16858 LiberationSerif-Italic.ttf::FontFile::3429051925918376143::1685898240::1685898240::1::::<><>:: LiberationSerif-Regular.ttf::FontFile::3437532725077625275::1685898240::1685898240::1::::<><>:: ::res://databases/::1685898240 -::res://Dialog/::1685898239 +::res://Dialog/::1685900633 dialog_system.gd::GDScript::-1::1685898239::0::1::::<>Node<>:: -TestDialog.tscn::PackedScene::4730621496714883874::1685898239::0::1::::<><>::res://Dialog/dialog_system.gd -::res://GenresSubstitution/::1685898239 +TestDialog.tscn::PackedScene::4730621496714883874::1685900633::0::1::::<><>::res://Dialog/dialog_system.gd +::res://GenresSubstitution/::1685900633 genre_sub.gd::GDScript::-1::1685898239::0::1::::<>Node<>:: -TestDB.tscn::PackedScene::3353206590719512815::1685898239::0::1::::<><>::res://GenresSubstitution/genre_sub.gd +TestDB.tscn::PackedScene::3353206590719512815::1685900633::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://Grammar/::1685900633 +ExceptionsForA.json::JSON::-1::1685900554::0::1::::<><>:: +ExceptionsForAn.json::JSON::-1::1685900489::0::1::::<><>:: +GrammarTest.gd::GDScript::-1::1685900631::0::1::::<>Node2D<>:: +GrammarTest.tscn::PackedScene::3628749051665588560::1685900633::0::1::::<><>::res://Grammar/GrammarTest.gd +::res://screens/::1685900633 +MainMenu.tscn::PackedScene::8771866178020998753::1685900633::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 diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/filesystem_update4 b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/filesystem_update4 index d33da54..2971ba3 100644 --- a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/filesystem_update4 +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/filesystem_update4 @@ -1,5 +1,7 @@ res://Grammar/GrammarTest.tscn res://Grammar/GrammarTest.gd +res://Grammar/ExceptionsForAn.json res://screens/MainMenu.tscn res://GenresSubstitution/TestDB.tscn res://Dialog/TestDialog.tscn +res://Grammar/ExceptionsForA.json diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/project_metadata.cfg b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/project_metadata.cfg index f73521a..d4a913a 100644 --- a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/project_metadata.cfg +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/project_metadata.cfg @@ -10,7 +10,7 @@ run_reload_scripts=true [recent_files] 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"] +scripts=["res://Grammar/ExceptionsForA.json", "res://Grammar/ExceptionsForAn.json", "res://Grammar/GrammarTest.gd", "res://Dialog/dialog_system.gd", "res://GenresSubstitution/genre_sub.gd"] [script_setup] diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/recent_dirs b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/recent_dirs new file mode 100644 index 0000000..8302d72 --- /dev/null +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/recent_dirs @@ -0,0 +1 @@ +/home/luke/Documents/ProgrammingProjects/RPGv3/bcirpg/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/script_editor_cache.cfg b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/script_editor_cache.cfg index 61e8d1f..b04e6f9 100644 --- a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/script_editor_cache.cfg +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/.godot/editor/script_editor_cache.cfg @@ -3,11 +3,11 @@ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 42, +"column": 30, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 49, -"scroll_position": 35.0, +"row": 135, +"scroll_position": 36.0, "selection": false, "syntax_highlighter": "GDScript" } @@ -19,9 +19,9 @@ state={ "breakpoints": PackedInt32Array(), "column": 51, "folded_lines": Array[int]([]), -"h_scroll_position": 117, +"h_scroll_position": 0, "row": 77, -"scroll_position": 49.0, +"scroll_position": 75.0, "selection": false, "syntax_highlighter": "GDScript" } @@ -31,11 +31,39 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 28, +"column": 25, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 46, -"scroll_position": 21.0, +"row": 78, +"scroll_position": 72.0, "selection": false, "syntax_highlighter": "GDScript" } + +[res://Grammar/ExceptionsForAn.json] + +state={ +"bookmarks": PackedInt32Array(), +"breakpoints": PackedInt32Array(), +"column": 7, +"folded_lines": Array[int]([]), +"h_scroll_position": 0, +"row": 3, +"scroll_position": 0.0, +"selection": false, +"syntax_highlighter": "JSON" +} + +[res://Grammar/ExceptionsForA.json] + +state={ +"bookmarks": PackedInt32Array(), +"breakpoints": PackedInt32Array(), +"column": 1, +"folded_lines": Array[int]([]), +"h_scroll_position": 0, +"row": 2, +"scroll_position": 0.0, +"selection": false, +"syntax_highlighter": "JSON" +} diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ExceptionsForA.json b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ExceptionsForA.json new file mode 100644 index 0000000..6df3b15 --- /dev/null +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ExceptionsForA.json @@ -0,0 +1,3 @@ +[ + "european" +] diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ExceptionsForAn.json b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ExceptionsForAn.json new file mode 100644 index 0000000..5892751 --- /dev/null +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/ExceptionsForAn.json @@ -0,0 +1,5 @@ +[ + "heir", + "hourglass", + "hour" +] diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/GrammarTest.gd b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/GrammarTest.gd index 78be13e..d04fb77 100644 --- a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/GrammarTest.gd +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/GrammarTest.gd @@ -1,10 +1,24 @@ extends Node2D -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - pass +var an_data_file_path = "res://Grammar/ExceptionsForAn.json" + +var exceptionsListForAn = load_json(an_data_file_path) +var a_data_file_path = "res://Grammar/ExceptionsForA.json" + +var exceptionsListForA = load_json(a_data_file_path) + +func load_json(filePath : String): + if(FileAccess.file_exists(filePath)): + + var dataFile = FileAccess.open(filePath, FileAccess.READ) + var parsedResult = JSON.parse_string(dataFile.get_as_text()) + + if parsedResult is Array: + return parsedResult + else: + print("Error Reading File") #rebuild_sentence is here to assist with making a human readable sentence, out of the array created in correct_sentence. @@ -43,9 +57,6 @@ 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 @@ -60,8 +71,10 @@ func correct_sentence(input_string: String) -> String: if current_word != last_word: if articleList.has(last_word): - if first_character.match("[aeiouAEIOU]") or exceptionsList.has(last_word): + if first_character.match("[aeiouAEIOU]") or exceptionsListForAn.has(last_word): newWords[i-1] = "an" + if exceptionsListForA.has(last_word): + newWords[i-1] = "a" else: newWords[i-1] = "a" @@ -69,8 +82,10 @@ func correct_sentence(input_string: String) -> String: 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]): + if nextWordFirstChar.match("[aeiouAEIOU]") or exceptionsListForAn.has(words[1]): newWords[0] = "An" + if exceptionsListForA.has(words[1]): + newWords[0] = "A" else: newWords[0] = "A" @@ -80,4 +95,8 @@ func correct_sentence(input_string: String) -> String: func _ready(): - print(correct_sentence("Eating seeds as an passtime activity...")) + print(correct_sentence("A heir and a hourglass to go to the throne")) + print(correct_sentence("An european country.")) + print(correct_sentence("A heir")) + print(correct_sentence("a hour")) +