<commit_before>{-# LANGUAGE LambdaCase, FlexibleInstances, FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans #-} -- TODO orphans? 
module Commands.Plugins.Spiros.Phrase.Run where
import Commands.Plugins.Spiros.Phrase.Types
import Commands.Plugins.Spiros.Phrase.Munging
import           Commands.Plugins.Spiros.Extra

import qualified Commands.Backends.OSX            as OSX
import           Commands.Plugins.Spiros.Phrase.Spacing
import Commands.Sugar.Keys

import           Data.List.NonEmpty               (NonEmpty (..))

import           Control.Monad ((>=>)) 


runPhrase_ :: Spacing -> OSX.ClipboardText -> Phrase -> String
runPhrase_ spacing clipboard
 = flip(mungePhrase) spacing
 . flip(splatPasted) clipboard
 . pPhrase
 . unPhrase

bestPhrase :: NonEmpty Phrase -> Phrase
bestPhrase = argmax rankPhrase

-- no list-generic instance, provides flexibility without OverlappingInstances  
instance Rankable Phrase where rank = rankPhrase
-- instance Rankable (Maybe Phrase) where rank = maybe defaultRank rankPhrase

instance Rankable Phrase_ where rank = rankPhrase_ 
instance Rankable Dictation where rank = rankDictation 

rankPhrase :: Phrase -> Int
rankPhrase = sum . fmap rankPhrase_ . unPhrase

-- the specificity ("probability") of the phrase parts. bigger is better.
rankPhrase_ :: Phrase_ -> Int
rankPhrase_ = \case
 Escaped_ _    -> 2 * highRank
 Quoted_ _     -> 2 * highRank
 Pasted_       -> defaultRank
 Clipboard_    -> defaultRank
 Blank_        -> defaultRank
 Capped_ cs    -> highRank + 3 * rankChars cs -- NOTE to recognize "caps mta" <commit_msg>fix "caps mta"<commit_after>{-# LANGUAGE LambdaCase, FlexibleInstances, FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans #-} -- TODO orphans? 
module Commands.Plugins.Spiros.Phrase.Run where
import Commands.Plugins.Spiros.Phrase.Types
import Commands.Plugins.Spiros.Phrase.Munging
import           Commands.Plugins.Spiros.Extra

import qualified Commands.Backends.OSX            as OSX
import           Commands.Plugins.Spiros.Phrase.Spacing
import Commands.Sugar.Keys

import           Data.List.NonEmpty               (NonEmpty (..))

import           Control.Monad ((>=>)) 


runPhrase_ :: Spacing -> OSX.ClipboardText -> Phrase -> String
runPhrase_ spacing clipboard
 = flip(mungePhrase) spacing
 . flip(splatPasted) clipboard
 . pPhrase
 . unPhrase

bestPhrase :: NonEmpty Phrase -> Phrase
bestPhrase = argmax rankPhrase

-- no list-generic instance, provides flexibility without OverlappingInstances  
instance Rankable Phrase where rank = rankPhrase
-- instance Rankable (Maybe Phrase) where rank = maybe defaultRank rankPhrase

instance Rankable Phrase_ where rank = rankPhrase_ 
instance Rankable Dictation where rank = rankDictation 

rankPhrase :: Phrase -> Int
rankPhrase = safeAverage . fmap rankPhrase_ . unPhrase

-- the specificity ("probability") of the phrase parts. bigger is better.
rankPhrase_ :: Phrase_ -> Int
rankPhrase_ = \case
 Escaped_ _    -> 2 * highRank
 Quoted_ _     -> 2 * highRank
 Pasted_       -> defaultRank
 Clipboard_    -> defaultRank
 Blank_        -> defaultRank
 Capped_ cs    -> highRank + 3 * rankChars cs -- NOTE to recognize "caps mta" 
{'fraction_non_alphanumeric': 0.08916030534351145, 'fraction_numerical': 0.00183206106870229, 'mean_word_length': 3.3855421686746987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4032467', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1021, 'n_words': 272}