4545
4646CONSECUTIVE_SPACES  =  re .compile (r"\s+" )
4747
48+ # Type alias for dict of token features. 
49+ FeatureDict  =  dict [str , str  |  bool ]
50+ 
4851
4952class  PreProcessor :
5053    """Recipe ingredient sentence PreProcessor class. 
@@ -972,7 +975,7 @@ def _ngram_features(self, token: str, prefix: str) -> dict[str, str]:
972975
973976        return  ngram_features 
974977
975-     def  _token_features (self , token : Token ) ->  dict [ str ,  str   |   bool ] :
978+     def  _token_features (self , token : Token ) ->  FeatureDict :
976979        """Return the features for the token at the given index in the sentence. 
977980
978981        If the token at the given index appears in the corpus parameter, the token is 
@@ -986,12 +989,12 @@ def _token_features(self, token: Token) -> dict[str, str | bool]:
986989
987990        Returns 
988991        ------- 
989-         dict[str, str | bool]  
992+         FeatureDict  
990993            Dictionary of features for token at index. 
991994        """ 
992995
993996        index  =  token .index 
994-         features : dict [ str ,  str   |   bool ]  =  {}
997+         features : FeatureDict  =  {}
995998
996999        features ["bias" ] =  "" 
9971000        features ["sentence_length" ] =  str (self ._sentence_length_bucket ())
@@ -1092,12 +1095,12 @@ def _token_features(self, token: Token) -> dict[str, str | bool]:
10921095
10931096        return  features 
10941097
1095-     def  sentence_features (self ) ->  list [dict [ str ,  str   |   bool ] ]:
1098+     def  sentence_features (self ) ->  list [FeatureDict ]:
10961099        """Return dict of features for each token in sentence. 
10971100
10981101        Returns 
10991102        ------- 
1100-         list[dict[str, str | bool] ] 
1103+         list[FeatureDict ] 
11011104            List of feature dicts for each token in sentence. 
11021105        """ 
11031106        logger .debug ("Generating features for tokens." )
0 commit comments