@@ -33,7 +33,7 @@ use crate::{
3333/// assert_eq!(
3434/// [
3535/// ("側", 1, 0).into(),
36- /// ("冊", 101 , 0).into(),
36+ /// ("冊", 100 , 0).into(),
3737/// ("測", 1, 0).into(),
3838/// ("策", 100, 0).into(),
3939/// ]
@@ -105,7 +105,7 @@ impl Dictionary for Layered {
105105 /// dictionaries.
106106 ///
107107 /// When a phrase appears in multiple dictionaries, the final
108- /// frequency is the sum of all frequency in all dictionaries.
108+ /// frequency is the max of all frequency in all dictionaries.
109109 ///
110110 /// Pseudo code
111111 ///
@@ -114,7 +114,7 @@ impl Dictionary for Layered {
114114 /// Foreach d in d_layers
115115 /// Foreach phrase, freq in d.lookup_syllables()
116116 /// If phrase in phrases
117- /// Set phrases[phrase].freq += freq
117+ /// Set phrases[phrase].freq = max(phrases[phrase]. freq, freq)
118118 /// Else
119119 /// Add phrases <- (phrase, freq)
120120 /// ```
@@ -128,7 +128,7 @@ impl Dictionary for Layered {
128128 match sort_map. entry ( phrase. to_string ( ) ) {
129129 Entry :: Occupied ( entry) => {
130130 let index = * entry. get ( ) ;
131- phrases[ index] . freq + = phrase. freq ;
131+ phrases[ index] . freq = phrase. freq . max ( phrases [ index ] . freq ) ;
132132 phrases[ index] . last_used =
133133 match ( phrases[ index] . last_used , phrase. last_used ) {
134134 ( Some ( orig) , Some ( new) ) => Some ( u64:: max ( orig, new) ) ,
@@ -326,7 +326,7 @@ mod tests {
326326 assert_eq ! (
327327 [
328328 ( "側" , 1 , 0 ) . into( ) ,
329- ( "冊" , 101 , 0 ) . into( ) ,
329+ ( "冊" , 100 , 0 ) . into( ) ,
330330 ( "測" , 1 , 0 ) . into( ) ,
331331 ( "策" , 100 , 0 ) . into( ) ,
332332 ]
@@ -375,7 +375,7 @@ mod tests {
375375 assert_eq ! (
376376 [
377377 ( "側" , 1 , 0 ) . into( ) ,
378- ( "冊" , 101 , 0 ) . into( ) ,
378+ ( "冊" , 100 , 0 ) . into( ) ,
379379 ( "測" , 1 , 0 ) . into( ) ,
380380 ( "策" , 100 , 0 ) . into( ) ,
381381 ]
0 commit comments