Re: Dictionary - StewartML
- Posted by "Stewart MacKenzie-Leigh" <stewartml89 at msn.com> Oct 28, 2003
- 404 views
Thanks for the suggestions. I should have realised about the equal function, but i just bashed it together in my spare time and i am not in the habit of having to use 'equal' (im a BASIC programmer mostly) and overlooked it. If i get some time, i'll upload the changed version. My main project at the moment is a scheduler to help treat procedures as seperate processes. its based on the langwar idea only it is more comprehensive. email me (stewart[PISSOFFSPAMMERS]ml89 at msn.com - remove the stuff in '[]') if you like the idea and any suggestions are welcome. >From: Irv <irvm at ellijay.com> >Reply-To: EUforum at topica.com >To: EUforum at topica.com >Subject: Dictionary - StewartML >Date: Mon, 27 Oct 2003 16:50:22 -0500 > > >Thanks for the wordlist, it will be useful for some games. >I have a few comments about dictionary.e which may help someone. > >1. for platform independence, remove both \n and \r when reading the text >file > >2. better to upcase the search word, and add an '*' if user forgets, >otherwise > wildcard match will fail even if the word is in the list. > >3 a. if dictionary[i] = word won't work, because you will be trying to >compare >words of different lengths. equal() works, but there's a better way. > >3b. find() is faster than a loop, except for very short lists of words. > finding 'ZOO' with a loop takes 5.74 seconds, > finding 'ZOO' with find() takes 2.17 seconds (1000 repetitions) > >See mods below. >Regards, >Irv > >include wildcard.e > >global sequence Dictionary > >global procedure LoadDictionary(sequence path) > integer fn > object temp > > fn = open(path, "r") > if fn = -1 then > printf(2, "Error opening the dictionary '%s'\n",{path}) > abort(1) > end if > > Dictionary = {} > > while 1 do > temp = gets(fn) > if atom(temp) then > exit > end if > > -- if temp[length(temp)] = '\n' then > -- temp = temp[1..length(temp) - 1] > -- end if > > while find('\n',temp)+find('\r',temp) do -- (1) > temp = temp[1..length(temp) - 1] > end while > > Dictionary = append(Dictionary, upper(temp)) > end while > > close(fn) >end procedure > > >global function FindMatchingWords(sequence dictionary, sequence string) > sequence words > > words = {} > > string = upper(string) -- (2) > if not find('*',string) then string &= "*" > end if > > for i = 1 to length(dictionary) do > if wildcard_match(string, dictionary[i]) then > words = append(words, dictionary[i]) > end if > end for > > return words >end function > > >global function IsWordInDictionary(sequence dictionary, sequence word) > >-- for i = 1 to length(dictionary) do -- (3a) > -- if dictionary[i] = word then -- err >-- if equal(dictionary[i],word) then -- slow >-- return i >-- end if >-- end for >-- return 0 > > return find(upper(word),dictionary) -- (3b) -- faster >end function >