I'm asked to modify the code I wrote such that in most of the functions I have to use either fldr or fldl
Here is the description which includes the test cases.
I'm wondering it would be great if you can give me some hint where I should modify to use those functions.
Due to lack of documentations and examples in ML I had to ask this question here
Thank you.
fun is_member [] x = false |
is_member (h::t) x = if (h=x) then true else is_member t x;
fun splitter string =
let
fun remove_c [] = [] |
remove_c (h::t) = (String.tokens (fn c => c = #":") h) @ (remove_c t)
fun remove_ex [] = [] |
remove_ex (h::t) = remove_c((String.tokens (fn c => c = #"!") h)) @ (remove_ex t)
fun remove_q [] = [] |
remove_q (h::t) = remove_ex((String.tokens (fn c => c = #"?") h)) @ (remove_q t)
fun remove_sc [] = [] |
remove_sc (h::t) = remove_q((String.tokens (fn c => c = #";") h)) @ (remove_sc t)
fun remove_dot [] = [] |
remove_dot (h::t) = remove_sc((String.tokens (fn c => c = #".") h)) @ (remove_dot t)
fun remove_nl [] = [] |
remove_nl (h::t) = remove_dot((String.tokens (fn c => c = #"\n") h)) @ (remove_nl t)
fun remove_tabs [] = [] |
remove_tabs (h::t) = remove_nl((String.tokens (fn c => c = #"\t") h)) @ (remove_tabs t)
fun remove_commas [] = [] |
remove_commas (h::t) = remove_tabs((String.tokens (fn c => c = #",") h)) @ (remove_commas t)
in
remove_commas((String.tokens (fn c => c = #" ") string))
end;
val stop_words = "a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,be,because,been,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,got,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,it,its,just,least,let,like,likely,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,said,say,says,she,should,since,so,some,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,yet,you,your";
val stop_word_list = splitter stop_words;
fun is_stop_word string =
let
fun f L = map (fn x => (is_member stop_word_list x)) L
in
f (splitter string)
end;
fun get_stop_words string =
let
fun get_stop [] x = x |
get_stop (h::t) x = if((is_member stop_word_list h = true) andalso ((is_member t h) = false)) then (get_stop t [h]@x) else (get_stop t x);
in
get_stop (splitter string) []
end;
fun remove_stop_words string =
let
fun remove_stop [] = [] |
remove_stop (h::t) = if(is_member stop_word_list h = true) then (remove_stop t) else [h]@(remove_stop t)
in
remove_stop(splitter string)
end;