Index: src/natools-smaz-tools.adb ================================================================== --- src/natools-smaz-tools.adb +++ src/natools-smaz-tools.adb @@ -774,21 +774,22 @@ end Filter_By_Count; function Simple_Dictionary (Counter : in Word_Counter; - Word_Count : in Natural) + Word_Count : in Natural; + Method : in Methods.Enum := Methods.Encoded) return String_Lists.List is use type Ada.Containers.Count_Type; Target_Count : constant Ada.Containers.Count_Type := Ada.Containers.Count_Type (Word_Count); Set : Scored_Word_Sets.Set; Result : String_Lists.List; begin for Cursor in Word_Maps.Iterate (Counter.Map) loop - Scored_Word_Sets.Include (Set, To_Scored_Word (Cursor)); + Scored_Word_Sets.Include (Set, To_Scored_Word (Cursor, Method)); if Scored_Word_Sets.Length (Set) > Target_Count then Scored_Word_Sets.Delete_Last (Set); end if; end loop; @@ -804,20 +805,21 @@ procedure Simple_Dictionary_And_Pending (Counter : in Word_Counter; Word_Count : in Natural; Selected : out String_Lists.List; Pending : out String_Lists.List; + Method : in Methods.Enum := Methods.Encoded; Max_Pending_Count : in Ada.Containers.Count_Type := Ada.Containers.Count_Type'Last) is use type Ada.Containers.Count_Type; Target_Count : constant Ada.Containers.Count_Type := Ada.Containers.Count_Type (Word_Count); Set : Scored_Word_Sets.Set; begin for Cursor in Word_Maps.Iterate (Counter.Map) loop - Scored_Word_Sets.Insert (Set, To_Scored_Word (Cursor)); + Scored_Word_Sets.Insert (Set, To_Scored_Word (Cursor, Method)); end loop; Selected := String_Lists.Empty_List; Pending := String_Lists.Empty_List; @@ -830,19 +832,28 @@ end if; end loop; end Simple_Dictionary_And_Pending; - function To_Scored_Word (Cursor : in Word_Maps.Cursor) + function To_Scored_Word + (Cursor : in Word_Maps.Cursor; + Method : in Methods.Enum) return Scored_Word is Word : constant String := Word_Maps.Key (Cursor); + Factor : Score_Value; begin + case Method is + when Methods.Encoded => Factor := Word'Length; + when Methods.Frequency => Factor := 1; + when Methods.Gain => Factor := Word'Length - 1; + end case; + return Scored_Word' (Size => Word'Length, Word => Word, - Score => Score_Value (Word_Maps.Element (Cursor)) * Word'Length); + Score => Score_Value (Word_Maps.Element (Cursor)) * Factor); end To_Scored_Word; function Worst_Index (Dict : in Dictionary; Index: src/natools-smaz-tools.ads ================================================================== --- src/natools-smaz-tools.ads +++ src/natools-smaz-tools.ads @@ -156,20 +156,22 @@ Threshold_Count : in String_Count); -- Remove from Counter all entries whose count is below the threshold function Simple_Dictionary (Counter : in Word_Counter; - Word_Count : in Natural) + Word_Count : in Natural; + Method : in Methods.Enum := Methods.Encoded) return String_Lists.List; -- Return the Word_Count words in Counter that have the highest score, -- the score being count * length. procedure Simple_Dictionary_And_Pending (Counter : in Word_Counter; Word_Count : in Natural; Selected : out String_Lists.List; Pending : out String_Lists.List; + Method : in Methods.Enum := Methods.Encoded; Max_Pending_Count : in Ada.Containers.Count_Type := Ada.Containers.Count_Type'Last); -- Return in Selected the Word_Count words in Counter that have the -- highest score, and in Pending the remaining words, -- the score being count * length. @@ -261,11 +263,13 @@ function "<" (Left, Right : Scored_Word) return Boolean is (Left.Score > Right.Score or else (Left.Score = Right.Score and then Left.Word < Right.Word)); - function To_Scored_Word (Cursor : in Word_Maps.Cursor) + function To_Scored_Word + (Cursor : in Word_Maps.Cursor; + Method : in Methods.Enum) return Scored_Word; package Scored_Word_Sets is new Ada.Containers.Indefinite_Ordered_Sets (Scored_Word);