<commit_before>module Types.Fwa
  ( Label
  , State
  , Transition (..)
  , Fwa (..)
  , states
  , labels
  ) where

import Data.List (nub, intersperse, intercalate)

type Label =
  String

type State =
  String

data Transition =
  Transition
    { label :: Label
    , state :: State
    , finalState :: State
    } deriving (Eq, Ord)

data Fwa =
  Fwa
    { startStates :: [State]
    , finalStates :: [State]
    , transitions :: [Transition]
    }

states :: Fwa -> [State]
states (Fwa startStates finalStates transitions) =
  nub (startStates ++ finalStates ++ concatMap mapper transitions)
    where
      mapper (Transition _ state finalState) = [state, finalState]

labels :: Fwa -> [Label]
labels (Fwa _ _ transitions) =
  nub (fmap state transitions)

instance Show Transition where
  show (Transition label state finalState) =
    label ++ "(" ++ state ++ ") -> " ++ finalState

instance Show Fwa where
  show fwa =
    printLabelList (labels fwa) ++ "\n\n" ++ printAutomaton fwa

printLabelList :: [Label] -> String
printLabelList labels =
  "Ops " ++ (unwords . fmap printLabelDecl) (labels ++ ["x"])

printLabelDecl :: Label -> String
printLabelDecl label =
  label ++ ":1"

printAutomaton :: Fwa -> String
printAutomaton fwa =
  "Automaton A\n"
  ++ "States " ++ unwords (states fwa) ++ "\n"
  ++ "Final States " ++ unwords (finalStates fwa) ++ "\n"
  ++ "Transitions\n"
  ++ "x -> " ++ head (startStates fwa) ++ "\n"
  ++ (intercalate "\n" . fmap show) (transitions fwa)
<commit_msg>Print all starting states<commit_after>module Types.Fwa
  ( Label
  , State
  , Transition (..)
  , Fwa (..)
  , states
  , labels
  ) where

import Data.List (nub, intersperse, intercalate)

type Label =
  String

type State =
  String

data Transition =
  Transition
    { label :: Label
    , state :: State
    , finalState :: State
    } deriving (Eq, Ord)

data Fwa =
  Fwa
    { startStates :: [State]
    , finalStates :: [State]
    , transitions :: [Transition]
    }

states :: Fwa -> [State]
states (Fwa startStates finalStates transitions) =
  nub (startStates ++ finalStates ++ concatMap mapper transitions)
    where
      mapper (Transition _ state finalState) = [state, finalState]

labels :: Fwa -> [Label]
labels (Fwa _ _ transitions) =
  nub (fmap state transitions)

instance Show Transition where
  show (Transition label state finalState) =
    label ++ "(" ++ state ++ ") -> " ++ finalState

instance Show Fwa where
  show fwa =
    printLabelList (labels fwa) ++ "\n\n" ++ printAutomaton fwa

printLabelList :: [Label] -> String
printLabelList labels =
  "Ops " ++ (unwords . fmap printLabelDecl) (labels ++ ["x"])

printLabelDecl :: Label -> String
printLabelDecl label =
  label ++ ":1"

printAutomaton :: Fwa -> String
printAutomaton fwa =
  "Automaton A\n"
  ++ "States " ++ unwords (states fwa) ++ "\n"
  ++ "Final States " ++ unwords (finalStates fwa) ++ "\n"
  ++ "Transitions\n"
  ++ printStartStates (startStates fwa) ++ "\n"
  ++ (intercalate "\n" . fmap show) (transitions fwa)

printStartStates :: [State] -> String
printStartStates =
  intercalate "\n" . fmap (\state -> "x -> " ++ state)

{'fraction_non_alphanumeric': 0.1425831202046036, 'fraction_numerical': 0.0006393861892583121, 'mean_word_length': 3.2398373983739837, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 19, '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': '868256', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1017, 'n_words': 300}