<commit_before>(*
 * OWL - an OCaml numerical library for scientific computing
 * Copyright (c) 2016-2017 <NAME> <<EMAIL>>
 *)

open Owl

let read_file f =
  let h = open_in f in
  let s = Utils.Stack.make () in
  (
    try while true do
      let l = input_line h in
      Utils.Stack.push s l;
    done with End_of_file -> ()
  );
  close_in h;
  Utils.Stack.to_array s

let write_file f s =
  let h = open_out f in
  Printf.fprintf h "%s" s;
  close_out h

let preprocess script =
  let lines = read_file script in
  (* FIXME: drop the first line *)
  let lines = Array.(sub lines 1 (length lines - 1)) in
  (* insert default configurations *)
  let lines = Array.append [| "#require \"owl\"" |] lines in
  let lines = Array.append [| "#use \"topfind\"" |] lines in
  (* join all the lines *)
  let s = Array.fold_left (fun a l -> a ^ l ^ "\n") "" lines in
  print_endline s;
  let new_script = "_" ^ (Filename.basename script) in
  write_file new_script s;
  new_script

let run script =
  let cmd = "ocaml " ^ script in
  Sys.command cmd

let _ =
  print_endline "Owl's Zoo System";
  let processed = preprocess Sys.argv.(1) in
  run processed
  (* run Sys.argv.(1) *)<commit_msg>design model zoo<commit_after>(*
 * OWL - an OCaml numerical library for scientific computing
 * Copyright (c) 2016-2017 <NAME> <<EMAIL>>
 *)

open Owl

let read_file f =
  let h = open_in f in
  let s = Utils.Stack.make () in
  (
    try while true do
      let l = input_line h |> String.trim in
      Utils.Stack.push s l;
    done with End_of_file -> ()
  );
  close_in h;
  Utils.Stack.to_array s


let write_file f s =
  let h = open_out f in
  Printf.fprintf h "%s" s;
  close_out h


let process_macro_zoo x =
  let id = String.(sub x 4 (length x - 4) |> trim) in
  let dir = Sys.getenv "HOME" ^ "/.owl/zoo/" ^ id in
  (* only include ml files *)
  let mls = Sys.readdir (dir)
    |> Utils.array_filter (fun s ->
        Filename.check_suffix s "ml"
      )
  in
  Array.fold_left (fun a l ->
    Printf.sprintf "%s#use \"%s/%s\"\n" a dir l
  ) "" mls


let preprocess script =
  let lines = read_file script in
  (* FIXME: drop the first line *)
  let lines = Array.(sub lines 1 (length lines - 1)) in
  (* insert default configurations *)
  let lines = Utils.array_insert lines 0 "#use \"topfind\"" in
  let lines = Utils.array_insert lines 1 "#require \"owl\"" in
  (* process zoo macros *)
  let lines = Array.map (fun l ->
    if String.length l >= 4 && String.sub l 0 4 = "#zoo" then (
      process_macro_zoo l
    )
    else l
  ) lines in
  (* join all the lines *)
  let s = Array.fold_left (fun a l -> a ^ l ^ "\n") "" lines in
  let new_script = "." ^ (Filename.basename script) in
  write_file new_script s;
  new_script


let run script =
  let cmd = "ocaml " ^ script in
  Sys.command cmd


let _ =
  print_endline "Owl's Zoo System";
  let processed = preprocess Sys.argv.(1) in
  run processed
{'fraction_non_alphanumeric': 0.1209094040647606, 'fraction_numerical': 0.010334137099552188, 'mean_word_length': 2.662042875157629, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, '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': '7270108', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1023, 'n_words': 373}