(* Copyright (C) 2007 Mauricio Fernandez http//eigenclass.org * See README.txt and LICENSE for the redistribution and modification terms *) let prefix = BM_search.make "GET /ongoing/When/" let re = "[0-9][0-9][0-9]x/\\([0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/[^ .]+\\) " let re = Str.regexp re let process_line hash str = try if Str.string_match re str (BM_search.find_end prefix str 0) then let k = Str.matched_group 1 str in Hashtbl.replace hash k (try Hashtbl.find hash k + 1 with Not_found -> 1) with Not_found -> () let sort_results hash = List.sort (fun (_,a) (_,b) -> b - a) (Hashtbl.fold (fun url hits l -> (url, hits) :: l) hash []) let rec print_top_n n = function [] -> () | ((url, hits) :: tl) -> if n > 0 then (Printf.printf "%d: %s\n" hits url; print_top_n (n-1) tl) let line_finder filename = let ic = open_in filename in let hash = Hashtbl.create 2000 in try while true do process_line hash (input_line ic) done with End_of_file -> print_top_n 10 (sort_results hash) let () = line_finder (Array.get Sys.argv 1)