<commit_before>module YakGraph(listOfClusterNames, listOfNodesPerCluster, countOfNodesPerCluster) where
import Data.GraphViz.Types
import Data.GraphViz.Types.Graph
import Data.GraphViz.Commands.IO
import qualified Data.Map as M
import Data.List(groupBy)
import Data.Maybe
import Data.Text.Lazy(unpack)
import Data.Sequence(Seq)
import Data.Foldable(toList)

fromGraphId (Str s) = unpack s

listOfClusterNames :: DotGraph String -> [String]
listOfClusterNames = map fromGraphId.map fromJust.M.keys. snd. graphStructureInformation

keyByCluster ((n,(p,_)):ns) = (p,n) : keyByCluster ns
keyByCluster []  =  []

extractClusterName :: Seq (Maybe GraphID) -> String
extractClusterName seq = case toList seq of
                          []                  -> "inbox"
                          (Just (Str name)):_ -> unpack name


listOfPairsToMapOfKeysWithListOfValues ::  [(Seq(Maybe GraphID),String)] -> M.Map String [String]
listOfPairsToMapOfKeysWithListOfValues pairs = groupStuff pairs M.empty
  where
    groupStuff [] m = m
    groupStuff ((c,n):rest) m =  M.alter (addToList n) (extractClusterName c) (groupStuff rest m)
    addToList  n Nothing = Just [n]
    addToList n (Just ns) = Just $ n:ns

countOfNodesPerCluster :: DotGraph String -> [(String, Int)]
countOfNodesPerCluster = map (\ (c,l) -> (c,length l)) . M.toList  .listOfNodesPerCluster


listOfNodesPerCluster :: DotGraph String -> M.Map String [String]
listOfNodesPerCluster =
 listOfPairsToMapOfKeysWithListOfValues . concatMap keyByCluster .groupBy sameCluster. M.toAscList . nodeInformation False
 where
  sameCluster (n,(p,_)) (n',(p',_)) = p == p' 
<commit_msg>one slice of data points for cfd<commit_after>module YakGraph(listOfClusterNames, listOfNodesPerCluster, countOfNodesPerCluster) where
import Data.GraphViz.Types
import Data.GraphViz.Types.Graph
import Data.GraphViz.Commands.IO
import qualified Data.Map as M
import Data.List(groupBy)
import Data.Maybe
import Data.Text.Lazy(unpack)
import Data.Sequence(Seq)
import Data.Foldable(toList)
import Control.Arrow

fromGraphId (Str s) = unpack s

listOfClusterNames :: DotGraph String -> [String]
listOfClusterNames = map fromGraphId.map fromJust.M.keys. snd. graphStructureInformation

keyByCluster ((n,(p,_)):ns) = (p,n) : keyByCluster ns
keyByCluster []  =  []

extractClusterName :: Seq (Maybe GraphID) -> String
extractClusterName seq = case toList seq of
                          []                  -> "inbox"
                          (Just (Str name)):_ -> unpack name


listOfPairsToMapOfKeysWithListOfValues ::  [(Seq(Maybe GraphID),String)] -> M.Map String [String]
listOfPairsToMapOfKeysWithListOfValues pairs = groupStuff pairs M.empty
  where
    groupStuff [] m = m
    groupStuff ((c,n):rest) m =  M.alter (addToList n) (extractClusterName c) (groupStuff rest m)
    addToList  n Nothing = Just [n]
    addToList n (Just ns) = Just $ n:ns

countOfNodesPerCluster :: DotGraph String -> [(String, Int)]
countOfNodesPerCluster = map (id *** length) . M.toList  .listOfNodesPerCluster


listOfNodesPerCluster :: DotGraph String -> M.Map String [String]
listOfNodesPerCluster =
 listOfPairsToMapOfKeysWithListOfValues . concatMap keyByCluster .groupBy sameCluster. M.toAscList . nodeInformation False
 where
  sameCluster (n,(p,_)) (n',(p',_)) = p == p' 

{'fraction_non_alphanumeric': 0.10770631067961164, 'fraction_numerical': 0.0, 'mean_word_length': 4.119565217391305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2296495', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1042, 'n_words': 275}