build_dictionary

build_dictionary - let inserter s t = match s[0 with'A'Z>...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
open Trie o let fname = "dictionary.txt" l (* Remove words that start with capitals *) (* Remove words with < 3 letters *) let read_dictionary file_name = let rec get_chars s acc = let len = String.length s in if len = 0 then acc else get_chars (String.sub s (0) (len -1)) (s.[len - 1]::acc) in let fold_lines f accum fname = let file = open_in fname in try let rec read_lines accum = let res = try Some (input_line file) with End_of_file -> None in match res with None -> accum | Some line -> read_lines (f line accum) in read_lines accum with exc -> close_in file; raise exc in
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: let inserter s t = match s.[0] with 'A'. .'Z' -> t | _ -> if String.length s < 3 then t else Trie.put (t) (get_chars s ) (Some(false)) in fold_lines inserter Trie.empty file_name let dictionary = read_dictionary fname;; let abacist = Trie.get dictionary ['a';'b';'a';'c';'i';'s';'t'];; let tan = Trie.get dictionary ['t';'a';'n'];; let polysyllabic = Trie.get dictionary ['p';'o';'l';'y';'s';'y';'l';'l';'a';'b';'i';'c'];; let aani = Trie.get dictionary ['A';'a';'n';'i'];;...
View Full Document

This note was uploaded on 10/25/2009 for the course CS 3110 at Cornell.

Ask a homework question - tutors are online