(defparameter *word-list-file-location* (uiop:parse-native-namestring "C:\\Users\\isoraqathedh\\Documents\\Programming\\mobyposi.i") "Location of which the list of words with part of speech modifiers are located.") (defun %reset-list () "Blank list for *master-word-list*" (loop with ht = (make-hash-table) for part-of-speech in '(:nouns ; Noun N :plurals ; Plural p :noun-phrases ; Noun Phrase h :verbs ; Verb (usu participle) V :transitive-verbs ; Verb (transitive) t :intransitive-verbs ; Verb (intransitive) i :adjectives ; Adjective A :adverbs ; Adverb v :conjunctions ; Conjunction C :prepositions ; Preposition P :interjections ; Interjection ! :pronouns ; Pronoun r :definite-articles ; Definite Article D :indef-articles ; Indefinite Article I :nominatives) ; Nominative o do (setf (gethash part-of-speech ht) (make-array 1500 :adjustable t :fill-pointer 0)) finally (return ht))) (defun reset-list () "Delete all entries from *master-word-list*." (setf *master-word-list* (%reset-list))) (defparameter *master-word-list* (%reset-list) "The word list holding all words and their parts of speech.") (defun refresh-list () "Reloads the list from mobiposi.i, replacing all entries orginally in *master-word-list*. Returns the number of items read." (reset-list) ; clear the original list. (with-open-file (stream *word-list* :external-format :utf-8) (loop for text = (read-line stream nil) for j from 0 while text for word = (subseq text 0 (position #\× text)) for codes = (subseq text (1+ (position #\× text))) for first-letter-then = #\- then first-letter-now for first-letter-now = (aref word 0) when (char-not-equal first-letter-then first-letter-now) do (princ (char-upcase first-letter-now)) do (mapcar #'(lambda (p) (vector-push-extend word (gethash p *master-word-list*))) (map 'list #'decode-pos-letter codes)) finally (return j)))) (defun decode-POS-letter (letter) "Turns the codes used by mobiposi.i into keywords corresponding to keys in the hash table." (ccase letter (#\N :nouns ) (#\p :plurals ) (#\h :noun-phrases ) (#\V :verbs ) (#\t :transitive-verbs ) (#\i :intransitive-verbs) (#\A :adjectives ) (#\v :adverbs ) (#\C :conjunctions ) (#\P :prepositions ) (#\! :interjections ) (#\r :pronouns ) (#\D :definite-articles ) (#\I :indef-articles ) (#\o :nominatives )))