<commit_before>{-# LANGUAGE OverloadedStrings #-} 

module Schema.Builder (build) where

import Signature.Types
import Data.Yaml
import qualified Data.ByteString.Char8 as B
  
arguments = object [
    "type"     .= String "array"
  , "additionalItems" .= False
  , "items"    .= array [
      object [
          "required" .= array [ String "fastq" ]
        , "additionalProperties" .= False
        , "type" .= String "object"
        , "properties" .= object [
            "fastq" .= object ["$ref" .= String "#/definitions/value"]
        ]
      ]
    ]
  ]

definitions = object [
    "value" .= object [ 
        "type" .= String "object"
      , "additionalProperties" .= False
      , "required" .= array [String "id", String "value", String "type"]
      , "properties" .= object [
          "id"    .= object ["type" .= String "string"]
        , "value" .= object ["type" .= String "string"]
        , "type"  .= object ["type" .= String "string"]
      ]
    ]
  ]

document = object [
    "$schema"  .= String "http://json-schema.org/draft-04/schema#"
  , "type"     .= String "object"
  , "additionalProperties" .= False
  , "properties" .= object [
          "version"   .= object ["type" .= String "string", "pattern" .= String "^0.9.\\d+$"]
        , "arguments" .= arguments 
      ]
  , "required" .= [String "arguments", String "version"]
  , "definitions" .= definitions
  ]

build :: [SigObj] -> Either String String
build _ = Right . B.unpack . encode $ document<commit_msg>Multiple arguments are parsed from signature<commit_after>{-# LANGUAGE OverloadedStrings #-} 

module Schema.Builder (build) where

import Signature.Types
import Data.Yaml

import qualified Data.ByteString.Char8  as B

argument x = object [
    "required" .= array [ String "fastq" ]
  , "additionalProperties" .= False
  , "type" .= String "object"
  , "properties" .= object [
      x .= object ["$ref" .= String "#/definitions/value"]
    ]
  ]

definitions = object [
    "value" .= object [ 
        "type" .= String "object"
      , "additionalProperties" .= False
      , "required" .= array [String "id", String "value", String "type"]
      , "properties" .= object [
          "id"    .= object ["type" .= String "string"]
        , "value" .= object ["type" .= String "string"]
        , "type"  .= object ["type" .= String "string"]
      ]
    ]
  ]

document terms = object [
    "$schema"  .= String "http://json-schema.org/draft-04/schema#"
  , "type"     .= String "object"
  , "additionalProperties" .= False
  , "required" .= [String "arguments", String "version"]
  , "definitions" .= definitions
  , "properties" .= object [
          "version"   .= object ["type" .= String "string", "pattern" .= String "^0.9.\\d+$"]
        , "arguments" .= object [
            "type"            .= String "array"
          , "additionalItems" .= False
          , "items"           .= array terms
        ]
      ]
  ]

term (Fastq _) = "fastq"
term (Fasta _) = "fasta"

build :: [SigObj] -> Either String String
build x = Right . B.unpack . encode $ document $ map (argument . term) x
{'fraction_non_alphanumeric': 0.17076326002587322, 'fraction_numerical': 0.003234152652005175, 'mean_word_length': 2.2799575821845175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4081595', 'n_tokens_mistral': 950, 'n_tokens_neox': 930, 'n_words': 247}