<commit_before>module Main where

-- Imports

import Util.Prelude
import Util.Parse
import Formula
import FormulaSyn
import System.Environment
import Skolem

-- Replace double-quotes (") to (\')
showToJSON :: Show a => a -> String
showToJSON = foldr (\x acc -> if x == '\"' then "\\\'" ++ acc else x:acc) [] . show

-- Make JSON object {"<s1>":"<s2>"}
makeJSONObject :: String -> String -> String
makeJSONObject s1 s2 = "\"" ++ s1 ++ "\":\"" ++ s2 ++ "\""

-- Make JSON with pnf, snf
makeJSON :: Formula -> String
makeJSON f = let body = formula ++ "," ++ parsed ++ "," ++ inPnf ++ "," ++ inSnf
                 formula = makeJSONObject "formula" $ showToJSON f
                 parsed  = makeJSONObject "parsed" $ showToJSON $ pPrint f
                 inPnf   = makeJSONObject "pnf" $ showToJSON $ pPrint $ pnf f
                 inSnf   = makeJSONObject "snf" $ showToJSON $ pPrint $ skolemize f
             in "{" ++ body ++  "}"

-- Print JSON of each formula
printJSONs :: [Formula] -> IO ()
printJSONs []   = return ()
printJSONs (x:xs) = do
   putStrLn $ makeJSON x
   printJSONs xs

main :: IO ()
main = do
   args <- getArgs
   let formulas :: [Formula] = map parse args
   printJSONs formulas<commit_msg>Fix JSON creation<commit_after>module Main where

-- Imports

import Util.Prelude
import Util.Parse
import Formula
import FormulaSyn
import System.Environment
import Skolem
import Unif

-- Replace double-quotes (") to (\')
showToJSON :: Show a => a -> String
showToJSON = foldr (\x acc -> if x == '\"' then "\\\'" ++ acc else x:acc) [] . show

-- Make JSON object {"<s1>":"<s2>"}
makeJSONObject :: String -> String -> String
makeJSONObject s1 s2 = "{\"" ++ s1 ++ "\":\"" ++ s2 ++ "\"}"

-- Make JSON list {"<s>" : [x1, x2 ...]"}
makeJSONList :: String -> [String] -> String
makeJSONList s [] = "\"" ++ s ++ "\":[]"
makeJSONList s xs = "\"" ++ s ++ "\":[" ++ foldr (\x acc -> x ++ ", " ++ acc) (last xs) (init xs) ++ "]"

-- Make JSON with pnfs, snfs
makeJSON :: [Formula] -> String
makeJSON f = let body = formulas ++ "," ++ parsed ++ "," ++ inPnf ++ "," ++ inSnf
                 formulas = makeJSONList "formulas" $ map (makeJSONObject "formula" . showToJSON) f
                 parsed   = makeJSONList "parsed_formulas" $ map (makeJSONObject "parsed" . showToJSON . pPrint) f
                 inPnf    = makeJSONList "pnfs" $ map (makeJSONObject "pnf" .showToJSON . pPrint . pnf) f
                 inSnf    = makeJSONList "snfs" $ map (makeJSONObject "snf" .showToJSON . pPrint . skolemize) f
             in "{" ++ body ++  "}"

-- Print JSON of each formula
printJSON :: [Formula] -> IO ()
printJSON = putStrLn . makeJSON

main :: IO ()
main = do
   args <- getArgs
   let formulas :: [Formula] = map parse args
   printJSON formulas

{'fraction_non_alphanumeric': 0.1683599419448476, 'fraction_numerical': 0.0050798258345428155, 'mean_word_length': 2.6468253968253967, 'pattern_counts': {'":': 6, '<': 10, '<?xml version=': 0, '>': 25, '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': '1005710', 'n_tokens_mistral': 909, 'n_tokens_neox': 893, 'n_words': 280}