diff options
Diffstat (limited to 'test/rat_tests-parse_graphs.adb')
-rw-r--r-- | test/rat_tests-parse_graphs.adb | 476 |
1 files changed, 416 insertions, 60 deletions
diff --git a/test/rat_tests-parse_graphs.adb b/test/rat_tests-parse_graphs.adb index 074bc27..701fbfc 100644 --- a/test/rat_tests-parse_graphs.adb +++ b/test/rat_tests-parse_graphs.adb @@ -11,114 +11,470 @@ package body Rat_Tests.Parse_Graphs is Prepositional_Phrase, Verb, Verb_Phrase, Sentence); package String_Tokens is new Packrat.Tokens (My_Labels, Character, String); - package Graphs is new Packrat.Parse_Graphs (My_Labels, Character, String, String_Tokens); + package Graphs is new Packrat.Parse_Graphs (My_Labels, Character, String, "<", String_Tokens); - Paper_Nodes : Graphs.Node_Array := - (1, -- Noun at position 1, value "i" - 2, -- Noun at position 4, value "man" - 3, -- Noun at position 7, value "park" - 4, -- Noun at position 10, value "bat" - 5, -- Determiner at position 3, value "a" - 6, -- Determiner at position 6, value "the" - 7, -- Determiner at position 9, value "a" - 8, -- Noun_Phrase at position 1 - 9, -- Noun_Phrase at position 3 - 10, -- Noun_Phrase at position 6 - 11, -- Noun_Phrase at position 9 - 12, -- Preposition at position 5, value "in" - 13, -- Preposition at position 8, value "with" - 14, -- Prepositional_Phrase at position 5 - 15, -- Prepositional_Phrase at position 8 - 16, -- Verb at position 2, value "saw" - 17, -- Verb_Phrase at position 2 - 18); -- Sentence at position 1 + -- These tokens are defined here purely to reduce verbosity when + -- manually constructing the various test graphs in the package initialisation. + Noun_1 : String_Tokens.Token := String_Tokens.Create (Noun, 1, "i"); + Noun_4 : String_Tokens.Token := String_Tokens.Create (Noun, 4, "man"); + Noun_7 : String_Tokens.Token := String_Tokens.Create (Noun, 7, "park"); + Noun_10 : String_Tokens.Token := String_Tokens.Create (Noun, 10, "bat"); - -- Cursors in Directed Graph library should be tagged - -- This will allow creation of an extended Cursor type in Parse Graphs - -- Edge labels need to contain group, finish, order, and restrict - -- The extended Cursor type should take the restrict into account with its functions + Det_3 : String_Tokens.Token := String_Tokens.Create (Determiner, 3, "a"); + Det_6 : String_Tokens.Token := String_Tokens.Create (Determiner, 6, "the"); + Det_9 : String_Tokens.Token := String_Tokens.Create (Determiner, 9, "a"); - -- There should be a validity checking function for Parse Graphs - -- There should also be a pretty print debug function for Parse Graphs + NP_1 : String_Tokens.Token := String_Tokens.Create (Noun_Phrase, 1, ""); + NP_3 : String_Tokens.Token := String_Tokens.Create (Noun_Phrase, 3, ""); + NP_6 : String_Tokens.Token := String_Tokens.Create (Noun_Phrase, 6, ""); + NP_9 : String_Tokens.Token := String_Tokens.Create (Noun_Phrase, 9, ""); + Prep_5 : String_Tokens.Token := String_Tokens.Create (Preposition, 5, "in"); + Prep_8 : String_Tokens.Token := String_Tokens.Create (Preposition, 8, "with"); + PP_5 : String_Tokens.Token := String_Tokens.Create (Prepositional_Phrase, 5, ""); + PP_8 : String_Tokens.Token := String_Tokens.Create (Prepositional_Phrase, 8, ""); - Paper_Edges : Graphs.Edge_Array := - ((1, 8, 1) -- Finish 2, Order 1 - (2, 9, 5) -- Finish 5, Order 1 - (3, 9, 2); -- Finish 5, Order 2 + Verb_2 : String_Tokens.Token := String_Tokens.Create (Verb, 2, "saw"); - Paper_Graph : Graphs.Parse_Graph := Graphs.To_Graph (Amb_Nodes, Amb_Edges, 18); + VP_2 : String_Tokens.Token := String_Tokens.Create (Verb_Phrase, 2, ""); + Sen_1 : String_Tokens.Token := String_Tokens.Create (Sentence, 1, ""); - function Root_Check + + -- This should be set up to be identical to the example parse in the paper + -- on pages 168-169. + + Paper_Graph : Graphs.Parse_Graph; + + + + + function Debug_String_Check + return String is + begin + return Paper_Graph.Debug_String; + end Debug_String_Check; + + + + + function Assign_Check return Test_Result is begin - end Root_Check; + -- to-do + return Fail; + end Assign_Check; - function Finish_List_Check + function Copy_Check return Test_Result is begin - end Finish_List_Check; + -- to-do + return Fail; + end Copy_Check; + + + function Move_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Move_Check; + + + + + + function Is_Empty_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Is_Empty_Check; - function Sub_Nodes_Check + function Clear_Check return Test_Result is begin - end Sub_Nodes_Check; + -- to-do + return Fail; + end Clear_Check; + + + + + + function Contains_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Contains_Check; + + + function Reachable_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Reachable_Check; + + + function All_Reachable_Check + return Test_Result + is + begin + -- to-do + return Fail; + end All_Reachable_Check; + + + function Valid_Starts_Finishes_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Valid_Starts_Finishes_Check; + + + function No_Loops_Introduced_Check + return Test_Result + is + begin + -- to-do + return Fail; + end No_Loops_Introduced_Check; + + + function Is_Sorted_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Is_Sorted_Check; + + + function No_Duplicates_Check + return Test_Result + is + begin + -- to-do + return Fail; + end No_Duplicates_Check; + + + + + + function Include_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Include_Check; + + + function Connect_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Connect_Check; function Prune_Check return Test_Result is begin + -- to-do + return Fail; end Prune_Check; - function Ambiguous_Check + function Delete_Unreachable_Check return Test_Result is begin - end Ambiguous_Check; + -- to-do + return Fail; + end Delete_Unreachable_Check; -begin - -- Node labels - Paper_Graph.Append_Label (1, String_Tokens.Create (Noun, 1, "i")); - Paper_Graph.Append_Label (2, String_Tokens.Create (Noun, 4, "man")); - Paper_Graph.Append_Label (3, String_Tokens.Create (Noun, 7, "park")); - Paper_Graph.Append_Label (4, String_Tokens.Create (Noun, 10, "bat")); - Paper_Graph.Append_Label (5, String_Tokens.Create (Determiner, 3, "a")); - Paper_Graph.Append_Label (6, String_Tokens.Create (Determiner, 6, "the")); - Paper_Graph.Append_Label (7, String_Tokens.Create (Determiner, 9, "a")); - Paper_Graph.Append_Label (8, String_Tokens.Create (Noun_Phrase, 1, "")); - Paper_Graph.Append_Label (9, String_Tokens.Create (Noun_Phrase, 3, "")); - Paper_Graph.Append_Label (10, String_Tokens.Create (Noun_Phrase, 6, "")); - Paper_Graph.Append_Label (11, String_Tokens.Create (Noun_Phrase, 9, "")); + function Has_Root_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Has_Root_Check; + + + function Set_Root_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Set_Root_Check; + + + function Clear_Root_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Clear_Root_Check; + + + function Root_Token_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Root_Token_Check; + + + function Root_Finish_List_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Root_Finish_List_Check; + + + function Root_Element_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Root_Element_Check; + + + + + + function Finish_List_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Finish_List_Check; + + + function Is_Leaf_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Is_Leaf_Check; + + + function Is_Branch_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Is_Branch_Check; + + - Paper_Graph.Append_Label (12, String_Tokens.Create (Preposition, 5, "in")); - Paper_Graph.Append_Label (13, String_Tokens.Create (Preposition, 8, "with")); - Paper_Graph.Append_Label (14, String_Tokens.Create (Prepositional_Phrase, 5, "")); - Paper_Graph.Append_Label (15, String_Tokens.Create (Prepositional_Phrase, 8, "")); - Paper_Graph.Append_Label (16, String_Tokens.Create (Verb, 2, "saw")); + function Subgroups_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Subgroups_Check; - Paper_Graph.Append_Label (17, String_Tokens.Create (Verb_Phrase, 2, "")); - Paper_Graph.Append_Label (18, String_Tokens.Create (Sentence, 1, "")); + function First_Index_Check + return Test_Result + is + begin + -- to-do + return Fail; + end First_Index_Check; + + + function Last_Index_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Last_Index_Check; + + + function Length_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Length_Check; + + + function Element_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Element_Check; + + + function Elements_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Elements_Check; + + + function Parent_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Parent_Check; + + + function Finish_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Finish_Check; + + + + + + function Is_Root_Ambiguous_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Is_Root_Ambiguous_Check; + + + function Is_Ambiguous_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Is_Ambiguous_Check; + + + function Ambiguities_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Ambiguities_Check; + + + + + + function Isomorphic_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Isomorphic_Check; + + + function Isomorphic_Subgraph_Check + return Test_Result + is + begin + -- to-do + return Fail; + end Isomorphic_Subgraph_Check; + + +begin - -- Edge labels + -- Constructing the various test graphs + + Paper_Graph.Connect ((NP_1, 2), + (1 => Graphs.Finished_Token'(Noun_1, 2))); + Paper_Graph.Connect ((NP_3, 5), + ((Det_3, 4), (Noun_4, 5))); + Paper_Graph.Connect ((NP_3, 8), + ((NP_3, 5), (PP_5, 8))); + Paper_Graph.Connect ((NP_3, 11), + ((NP_3, 5), (PP_5, 11))); + Paper_Graph.Connect ((NP_3, 11), + ((NP_3, 8), (PP_8, 11))); + Paper_Graph.Connect ((NP_6, 8), + ((Det_6, 7), (Noun_7, 8))); + Paper_Graph.Connect ((NP_6, 11), + ((NP_6, 8), (PP_8, 11))); + Paper_Graph.Connect ((NP_9, 11), + ((Det_9, 10), (Noun_10, 11))); + + Paper_Graph.Connect ((PP_5, 8), + ((Prep_5, 6), (NP_6, 8))); + Paper_Graph.Connect ((PP_5, 11), + ((Prep_5, 6), (NP_6, 11))); + Paper_Graph.Connect ((PP_8, 11), + ((Prep_8, 9), (NP_9, 11))); + + Paper_Graph.Connect ((VP_2, 5), + ((Verb_2, 3), (NP_3, 5))); + Paper_Graph.Connect ((VP_2, 8), + ((Verb_2, 3), (NP_3, 8))); + Paper_Graph.Connect ((VP_2, 11), + ((Verb_2, 3), (NP_3, 11))); + + Paper_Graph.Connect ((Sen_1, 5), + ((NP_1, 2), (VP_2, 5))); + Paper_Graph.Connect ((Sen_1, 8), + ((NP_1, 2), (VP_2, 8))); + Paper_Graph.Connect ((Sen_1, 8), + ((Sen_1, 5), (PP_5, 8))); + Paper_Graph.Connect ((Sen_1, 11), + ((NP_1, 2), (VP_2, 11))); + Paper_Graph.Connect ((Sen_1, 11), + ((Sen_1, 5), (PP_5, 11))); + Paper_Graph.Connect ((Sen_1, 11), + ((Sen_1, 8), (PP_8, 11))); end Rat_Tests.Parse_Graphs; |