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.

This commit is contained in:
PersonGuyGit 2023-06-04 12:59:28 -06:00
parent 0272a3821d
commit 24b1d2c772
11 changed files with 96 additions and 30 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -0,0 +1 @@
/home/luke/Documents/ProgrammingProjects/RPGv3/bcirpg/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/Grammar/

View File

@ -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"
}

View File

@ -0,0 +1,3 @@
[
"european"
]

View File

@ -0,0 +1,5 @@
[
"heir",
"hourglass",
"hour"
]

View File

@ -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"))