tree-features: c1bc94eeea439c3a12f2d099b3befa238d6e5fe3

     1: module Program where
     2: 
     3: import Data.List
     4: import System.Environment
     5: import Text.XML.Light.Input
     6: import Text.XML.Light.Types
     7: import Features
     8: import SexprHelper
     9: import XmlHelper
    10: import Numeric (showHex, showIntAtBase)
    11: import Data.Char (intToDigit)
    12: 
    13: -- Helpers for Main.hs, kept separate to ease testing
    14: 
    15: getBits :: IO Int
    16: getBits = do bits <- lookupEnv "BITS"
    17:              return $ case bits of
    18:                            Nothing -> defaultBits
    19:                            Just n  -> read n
    20: 
    21: defaultBits :: (Integral a) => a
    22: defaultBits = 31
    23: 
    24: parse :: String -> TreeOf String
    25: parse = parseSexpr
    26: 
    27: mainTemplate' bits = extractFeatures' . fmap (feature (fromIntegral bits))
    28:                                       . parse
    29: 
    30: mainTemplate bits input = numsOf bits (mainTemplate' bits input)
    31: 
    32: numsOf nums fv = let padded = padTo (fromIntegral nums) fv
    33:                  in  addCommas (map show padded)
    34: 
    35: addCommas :: [String] -> String
    36: addCommas = intercalate ","
    37: 
    38: padTo :: Int -> FeatureVector -> FeatureVector
    39: padTo n fv | length fv >= n = reverse (take n (reverse fv))
    40: padTo n fv                  = padTo n (fv ++ [0])
    41: 
    42: mainWithBits = do bits  <- getBits
    43:                   input <- getContents
    44:                   putStrLn (mainTemplate bits input)

Generated by git2html.