<commit_before>{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns      #-}

-- Module      : Data.Text.Case.Types
-- Copyright   : (c) 2014 <NAME> <<EMAIL>>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)

module Data.Text.Case.Types where

import           Control.Monad
import qualified Data.Char           as Char
import           Data.Monoid
import           Data.Text.Buildable

newtype Ordinal a = Ordinal a

instance Integral a => Buildable (Ordinal a) where
    build (Ordinal (toInteger -> n)) = build n <> suf
      where
        suf | x `elem` [11..13] = "th"
            | y == 1            = "st"
            | y == 2            = "nd"
            | y == 3            = "rd"
            | otherwise         = "th"

        (flip mod 100 -> x, flip mod 10 -> y) = join (,) (abs n)

isBoundary :: Char -> Bool
isBoundary c = Char.isSpace c || c == '-' || c == '_'

isWordBoundary :: Char -> Bool
isWordBoundary c = isBoundary c || Char.isUpper c
<commit_msg>Boundary documentation<commit_after>{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns      #-}

-- Module      : Data.Text.Case.Types
-- Copyright   : (c) 2014 <NAME> <<EMAIL>>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)

module Data.Text.Case.Types where

import           Control.Monad
import qualified Data.Char           as Char
import           Data.Monoid
import           Data.Text.Buildable

newtype Ordinal a = Ordinal a

instance Integral a => Buildable (Ordinal a) where
    build (Ordinal (toInteger -> n)) = build n <> suf
      where
        suf | x `elem` [11..13] = "th"
            | y == 1            = "st"
            | y == 2            = "nd"
            | y == 3            = "rd"
            | otherwise         = "th"

        (flip mod 100 -> x, flip mod 10 -> y) = join (,) (abs n)

-- | Returns 'True' for any boundary or uppercase character.
isWordBoundary :: Char -> Bool
isWordBoundary c = isBoundary c || Char.isUpper c

-- | Returns 'True' for any boundary character.
isBoundary :: Char -> Bool
isBoundary c = Char.isSpace c || c == '-' || c == '_'

{'fraction_non_alphanumeric': 0.12665684830633284, 'fraction_numerical': 0.014727540500736377, 'mean_word_length': 1.8243243243243243, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, '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': '1525022', 'n_tokens_mistral': 870, 'n_tokens_neox': 819, 'n_words': 287}