user-defined.scm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (library (user-defined)
  2. (export data/filter
  3. get-learned
  4. get-not-learned
  5. filter-attributes
  6. default-filter-word-attr
  7. train-not-learned
  8. display-word)
  9. (import (except (rnrs base)
  10. vector-map
  11. vector-for-each)
  12. (only (guile)
  13. lambda* λ
  14. ;; control structures
  15. when
  16. ;; output
  17. display
  18. simple-format
  19. ;; strings
  20. string-join
  21. string=)
  22. (ice-9 pretty-print)
  23. (srfi srfi-1) ; lists
  24. (srfi srfi-43) ; vectors
  25. (vector-utils)
  26. (alist-utils)
  27. (random-utils)
  28. (prefix (io) io:)
  29. (model))
  30. ;;; Add your own procedures here.
  31. (define data/filter
  32. (lambda* (data accessor condition #:key (filter vector-filter))
  33. "Access part of a data structure DATA using ACCESSOR and
  34. filter that part using CONDITION."
  35. (filter (λ (item) (condition item))
  36. (accessor data))))
  37. (define filter-attributes
  38. (λ (word
  39. metadata-attr-pred
  40. translation-data-attr-pred)
  41. `(("metadata"
  42. . ,(filter metadata-attr-pred
  43. (alist-refs word '("metadata"))))
  44. ("translation-data"
  45. . ,(filter translation-data-attr-pred
  46. (alist-refs word '("translation-data")))))))
  47. (define default-filter-word-attr
  48. (λ (ind word)
  49. (filter-attributes word
  50. (λ (meta-datum)
  51. (and (not (string= (car meta-datum) "usage-examples"))
  52. (not (string= (car meta-datum) "tags"))
  53. (not (string= (car meta-datum) "explanations"))))
  54. (λ (translation-datum)
  55. (and
  56. (not (string= (car translation-datum) "simplified"))
  57. (not (string= (car translation-datum) "traditional"))
  58. (not (string= (car translation-datum) "phonetic-script")))))))
  59. (define train-not-learned
  60. (λ (voc)
  61. (let ([not-learned
  62. (vector-map default-filter-word-attr
  63. (vocabulary-words voc))])
  64. (vector-for-each (λ (ind word)
  65. ;; (alist-print word)
  66. (io:read-line))
  67. not-learned)))))