Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | tools/smaz: use scoring from Natools.Smaz.Tools |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
99442da1d73149ddf8893378cbe2e732 |
User & Date: | nat 2016-11-08 20:44:53 |
Context
2016-11-09
| ||
21:14 | smaz-tools: add scoring method support in simple dictionary building check-in: 90573face2 user: nat tags: trunk | |
2016-11-08
| ||
20:44 | tools/smaz: use scoring from Natools.Smaz.Tools check-in: 99442da1d7 user: nat tags: trunk | |
2016-11-07
| ||
21:11 | smaz-tools: import scoring code from tools/smaz check-in: 5822fc18e0 user: nat tags: trunk | |
Changes
Changes to tools/smaz.adb.
︙ | ︙ | |||
36 37 38 39 40 41 42 | procedure Smaz is function To_SEA (S : String) return Ada.Streams.Stream_Element_Array renames Natools.S_Expressions.To_Atom; package Holders is new Ada.Containers.Indefinite_Holders (Natools.Smaz.Dictionary, Natools.Smaz."="); | | < < < < | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | procedure Smaz is function To_SEA (S : String) return Ada.Streams.Stream_Element_Array renames Natools.S_Expressions.To_Atom; package Holders is new Ada.Containers.Indefinite_Holders (Natools.Smaz.Dictionary, Natools.Smaz."="); package Methods renames Natools.Smaz.Tools.Methods; package Actions is type Enum is (Nothing, Decode, Encode, Evaluate); end Actions; package Dict_Sources is type Enum is (S_Expression, Text_List, Unoptimized_Text_List); end Dict_Sources; package Options is type Id is (Output_Ada_Dict, Dictionary_Input, Decode, Encode, Evaluate, |
︙ | ︙ | |||
132 133 134 135 136 137 138 | Counts : out Natools.Smaz.Tools.Dictionary_Counts); -- Dispatch to parallel or non-parallel version of Evaluate_Dictionary -- depending on Job_Count. function Getopt_Config return Getopt.Configuration; -- Build the configuration object | < < < < < < < | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | Counts : out Natools.Smaz.Tools.Dictionary_Counts); -- Dispatch to parallel or non-parallel version of Evaluate_Dictionary -- depending on Job_Count. function Getopt_Config return Getopt.Configuration; -- Build the configuration object procedure Optimization_Round (Dict : in out Holders.Holder; Score : in out Ada.Streams.Stream_Element_Count; Counts : in out Natools.Smaz.Tools.Dictionary_Counts; Pending_Words : in out Natools.Smaz.Tools.String_Lists.List; Input_Texts : in Natools.Smaz.Tools.String_Lists.List; Job_Count : in Natural; |
︙ | ︙ | |||
185 186 187 188 189 190 191 | -- print the given dictionary in the given file procedure Print_Help (Opt : in Getopt.Configuration; Output : in Ada.Text_IO.File_Type); -- Print the help text to the given file | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | -- print the given dictionary in the given file procedure Print_Help (Opt : in Getopt.Configuration; Output : in Ada.Text_IO.File_Type); -- Print the help text to the given file function To_Dictionary (Handler : in Callback'Class; Input : in Natools.Smaz.Tools.String_Lists.List) return Natools.Smaz.Dictionary; -- Convert the input into a dictionary given the option in Handler overriding procedure Option (Handler : in out Callback; Id : in Options.Id; Argument : in String) is begin case Id is |
︙ | ︙ | |||
416 417 418 419 420 421 422 | Updated : out Boolean) is use type Ada.Streams.Stream_Element_Offset; New_Value : Ada.Strings.Unbounded.Unbounded_String; New_Position : Natools.Smaz.Tools.String_Lists.Cursor; Worst_Index : constant Ada.Streams.Stream_Element | | | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | Updated : out Boolean) is use type Ada.Streams.Stream_Element_Offset; New_Value : Ada.Strings.Unbounded.Unbounded_String; New_Position : Natools.Smaz.Tools.String_Lists.Cursor; Worst_Index : constant Ada.Streams.Stream_Element := Natools.Smaz.Tools.Worst_Index (Dict.Element, Counts, Method); Worst_Value : constant String := Natools.Smaz.Dict_Entry (Dict.Element, Worst_Index); Worst_Count : constant Natools.Smaz.Tools.String_Count := Counts (Worst_Index); Base : constant Natools.Smaz.Dictionary := Natools.Smaz.Tools.Remove_Element (Dict.Element, Worst_Index); Old_Score : constant Ada.Streams.Stream_Element_Count := Score; |
︙ | ︙ | |||
845 846 847 848 849 850 851 | (Natools.Smaz.Tools.Simple_Dictionary (Counter, 254), Handler.Vlen_Verbatim); end if; end; end case; end To_Dictionary; | < < < < < < < < < < < < < < < < < < < < < < < | 791 792 793 794 795 796 797 798 799 800 801 802 803 804 | (Natools.Smaz.Tools.Simple_Dictionary (Counter, 254), Handler.Vlen_Verbatim); end if; end; end case; end To_Dictionary; Opt_Config : constant Getopt.Configuration := Getopt_Config; Handler : Callback; Input_List, Input_Data : Natools.Smaz.Tools.String_Lists.List; begin Process_Command_Line : begin |
︙ | ︙ | |||
1072 1073 1074 1075 1076 1077 1078 | end if; if Handler.Stat_Output then declare procedure Print (Label : in String; E : in Ada.Streams.Stream_Element; | | | | | | | | | > | | | 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 | end if; if Handler.Stat_Output then declare procedure Print (Label : in String; E : in Ada.Streams.Stream_Element; Score : in Natools.Smaz.Tools.Score_Value); procedure Print_Min_Max (Label : in String; Score : not null access function (D : in Natools.Smaz.Dictionary; C : in Natools.Smaz.Tools.Dictionary_Counts; E : in Ada.Streams.Stream_Element) return Natools.Smaz.Tools.Score_Value); procedure Print_Value (Label : in String; Score : not null access function (D : in Natools.Smaz.Dictionary; C : in Natools.Smaz.Tools.Dictionary_Counts; E : in Ada.Streams.Stream_Element) return Natools.Smaz.Tools.Score_Value; Ref : in Natools.Smaz.Tools.Score_Value); procedure Print (Label : in String; E : in Ada.Streams.Stream_Element; Score : in Natools.Smaz.Tools.Score_Value) is begin if Handler.Sx_Output then Sx_Output.Open_List; Sx_Output.Append_Atom ((0 => E)); Sx_Output.Append_String (Natools.Smaz.Dict_Entry (Dictionary, E)); Sx_Output.Append_String (Ada.Strings.Fixed.Trim (Score'Img, Ada.Strings.Both)); Sx_Output.Close_List; else Ada.Text_IO.Put_Line (Label & Ada.Characters.Latin_1.HT & Ada.Streams.Stream_Element'Image (E) & Ada.Characters.Latin_1.HT & Natools.String_Escapes.C_Escape_Hex (Natools.Smaz.Dict_Entry (Dictionary, E), True) & Ada.Characters.Latin_1.HT & Score'Img); end if; end Print; procedure Print_Min_Max (Label : in String; Score : not null access function (D : in Natools.Smaz.Dictionary; C : in Natools.Smaz.Tools.Dictionary_Counts; E : in Ada.Streams.Stream_Element) return Natools.Smaz.Tools.Score_Value) is use type Natools.Smaz.Tools.Score_Value; Min_Score, Max_Score : Natools.Smaz.Tools.Score_Value := Score (Dictionary, Counts, 0); S : Natools.Smaz.Tools.Score_Value; begin for E in 1 .. Dictionary.Dict_Last loop S := Score (Dictionary, Counts, E); if S < Min_Score then Min_Score := S; end if; if S > Max_Score then |
︙ | ︙ | |||
1150 1151 1152 1153 1154 1155 1156 | procedure Print_Value (Label : in String; Score : not null access function (D : in Natools.Smaz.Dictionary; C : in Natools.Smaz.Tools.Dictionary_Counts; E : in Ada.Streams.Stream_Element) | | | > > | > | > | > | 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | procedure Print_Value (Label : in String; Score : not null access function (D : in Natools.Smaz.Dictionary; C : in Natools.Smaz.Tools.Dictionary_Counts; E : in Ada.Streams.Stream_Element) return Natools.Smaz.Tools.Score_Value; Ref : in Natools.Smaz.Tools.Score_Value) is use type Natools.Smaz.Tools.Score_Value; begin if Handler.Sx_Output then Sx_Output.Open_List; Sx_Output.Append_String (Label); end if; for E in Dictionary.Offsets'Range loop if Score (Dictionary, Counts, E) = Ref then Print (Label, E, Ref); end if; end loop; if Handler.Sx_Output then Sx_Output.Close_List; end if; end Print_Value; begin Print_Min_Max ("encoded", Natools.Smaz.Tools.Score_Encoded'Access); Print_Min_Max ("frequency", Natools.Smaz.Tools.Score_Frequency'Access); Print_Min_Max ("gain", Natools.Smaz.Tools.Score_Gain'Access); end; end if; end; end case; end Build_Dictionary; end Smaz; |