Plaster
New
List
Login
text
default
isoraqathedh
1944.10.18 13:04:28
3-D×AN 4-F×N 4-H'er×N 4-H×A A battery×h a bon march×v a cappella×Av a capriccio×h a datu×h a fortiori×v a gogo×Av A horizon×h a la carte×Av a la king×A a la mode×A a la×P A level×h a posteriori×A a priori×A a punta d'arco×h a quo×h a rivederci×h A supply×h a tempo×Avh a tergo×h a vinculo matrimonii×h a vol×h a'×A A-1×N A-axis×N A-bomb×N A-frame×N A-line×NA A-OK×A A-pole×N A-Z test×h A/C×N A/m×N A/O×N A/P×N A/V×N A1c×N A1×A AAAA×N AAAL×N AAAS×N AAA×N Aaberg×N Aachen×N AAEE×N AAeE×N AAE×N AAF×N AAgr×N AAG×N Aalborg×N Aalesund×N aalii×N Aalst×N Aalto×N AAM×N AAPSS×N AAP×N Aarau×N Aara×N aardvark×N aardwolf×N aardwolves×p Aaren×N Aargau×N Aarhus×N Aarika×N Aaron's beard×h Aaron's rod×h Aaron's-beard×N Aaronical×A Aaronic×A Aaronite×N Aaronitic×A Aaronson×N
Raw
Annotate
Repaste
Annotations
text
default
shinmera
1944.10.18 13:23:09
;;;;; ;; Very easy but inefficient (defvar *words* (make-hash-table)) (defun add-word (word type) (push word (gethash type *words*))) (defun process (line) (loop with word = NIL for i from 0 below (length line) for char = (aref line i) do (cond ((eql char #\MULTIPLICATION_SIGN) (setf word (subseq line 0 i))) (word (add-word word char))))) (defun process-stream (stream) (loop for line = (read-line stream NIL NIL) while line do (process line))) (defun process-file (pathname &key (if-does-not-exist :error)) (with-open-file (stream pathname :if-does-not-exist if-does-not-exist) (process-stream stream))) ;;;;; ;; Now the same, but with vectors. (defvar *words* (make-hash-table)) (defun ensure-word-vector (type) (or (gethash type *words*) (setf (gethash type *words*) (make-array 0 :adjustable T :fill-pointer T)))) (defun add-word (word type) (vector-push-extend word (ensure-word-vector type))) ;; rest stays the same ;;;;; ;; Now the same but with a vector instead of words list. (defvar *words* (make-array (char-code #\z))) (defun words (type) (aref *words* (char-code type))) (defun (setf words) (vector type) (setf (aref *words* (char-code type)) vector)) (defun ensure-word-vector (type) (or (words type) (setf (words type) (make-array 0 :adjustable T :fill-pointer T)))) ;; rest stays the same ;;; Personally I would go with the hash-table+vector solution.
Raw
Repaste
text
default
isoraqathedh
1944.10.18 17:54:17
(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 )))
Raw
Repaste
text
default
shinmera
1944.10.18 18:04:56
(defun modify-file (in function &optional (out in)) (let ((content (with-open-file (stream in :direction :input) (with-output-to-string (string) (let ((buffer (make-array 4096 :element-type 'character))) (loop for bytes = (read-sequence buffer stream) do (write-sequence buffer string :start 0 :end bytes) while (= bytes 4096))))))) (with-open-file (stream out :direction :output :if-exists :supersede) (write-sequence (funcall function content) stream)))) (modify-file #p"wordlist.txt" #'(lambda (a) (cl-ppcre:regex-replace-all "([^×]*)×(.*)\\n" a "\\2 \\1 ")))
Raw
Repaste