<commit_before>-----------------------------------------------------------------------------
-- Copyright 2010, Open Universiteit Nederland. This file is distributed 
-- under the terms of the GNU General Public License. For more information, 
-- see the file "LICENSE.txt", which is included in the distribution.
-----------------------------------------------------------------------------
-- |
-- Maintainer  :  <EMAIL>
-- Stability   :  provisional
-- Portability :  portable (depends on ghc)
--
-----------------------------------------------------------------------------
module Service.Request where

import Common.Library hiding (exerciseId)
import Data.Char

data Request = Request
   { service    :: String
   , exerciseId :: Maybe Id
   , source     :: Maybe String
   , dataformat :: DataFormat
   , encoding   :: Maybe Encoding
   }
   
data DataFormat = XML | JSON 

data Encoding = OpenMath | StringEncoding
   
discoverDataFormat :: Monad m => String -> m DataFormat
discoverDataFormat xs =
   case dropWhile isSpace xs of
      '<':_ -> return XML
      '{':_ -> return JSON
      _     -> fail "Unknown data format"

readEncoding :: Monad m => String -> m Encoding
readEncoding xs =
   case map toLower xs of
      "openmath" -> return OpenMath
      "string"   -> return StringEncoding
      _          -> fail $ "Invalid encoding: " ++ xs<commit_msg>deriving show needed for logging database<commit_after>-----------------------------------------------------------------------------
-- Copyright 2010, Open Universiteit Nederland. This file is distributed 
-- under the terms of the GNU General Public License. For more information, 
-- see the file "LICENSE.txt", which is included in the distribution.
-----------------------------------------------------------------------------
-- |
-- Maintainer  :  <EMAIL>
-- Stability   :  provisional
-- Portability :  portable (depends on ghc)
--
-----------------------------------------------------------------------------
module Service.Request where

import Common.Library hiding (exerciseId)
import Data.Char

data Request = Request
   { service    :: String
   , exerciseId :: Maybe Id
   , source     :: Maybe String
   , dataformat :: DataFormat
   , encoding   :: Maybe Encoding
   }
   
data DataFormat = XML | JSON 
   deriving Show

data Encoding = OpenMath | StringEncoding
   deriving Show

discoverDataFormat :: Monad m => String -> m DataFormat
discoverDataFormat xs =
   case dropWhile isSpace xs of
      '<':_ -> return XML
      '{':_ -> return JSON
      _     -> fail "Unknown data format"

readEncoding :: Monad m => String -> m Encoding
readEncoding xs =
   case map toLower xs of
      "openmath" -> return OpenMath
      "string"   -> return StringEncoding
      _          -> fail $ "Invalid encoding: " ++ xs
{'fraction_non_alphanumeric': 0.2422293676312969, 'fraction_numerical': 0.0028581636298678098, 'mean_word_length': 1.585410895660203, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4786636', 'n_tokens_mistral': 672, 'n_tokens_neox': 657, 'n_words': 244}