wadoku.scm
| 1 | ;;; Nani Project website |
| 2 | ;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu> |
| 3 | ;;; |
| 4 | ;;; This file is part of the Nani Project website. |
| 5 | ;;; |
| 6 | ;;; The Nani Project website is free software; you can redistribute it and/or modify it |
| 7 | ;;; under the terms of the GNU Affero General Public License as published by |
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at |
| 9 | ;;; your option) any later version. |
| 10 | ;;; |
| 11 | ;;; The Nani Project website is distributed in the hope that it will be useful, but |
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | ;;; GNU Affero General Public License for more details. |
| 15 | ;;; |
| 16 | ;;; You should have received a copy of the GNU Affero General Public License |
| 17 | ;;; along with the Nani Project website. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | (use-modules (nani pitch wadoku)) |
| 20 | (use-modules (nani pitch pitch)) |
| 21 | (use-modules (nani result frequency)) |
| 22 | (use-modules (nani result result)) |
| 23 | (use-modules (nani result wadoku)) |
| 24 | (use-modules (ice-9 match)) |
| 25 | (use-modules (ice-9 binary-ports)) |
| 26 | |
| 27 | ;; Break these steps to try and let the GC reclaim these big objects |
| 28 | (define (get-results1 input frq) |
| 29 | (call-with-input-file input |
| 30 | (lambda (port) |
| 31 | (xml->results port frq)))) |
| 32 | |
| 33 | (define (get-results input meaning-filter frq) |
| 34 | (let* ((results (get-results1 input frq)) |
| 35 | (results (map (lambda (result) |
| 36 | (update-result |
| 37 | result |
| 38 | #:meanings (filter meaning-filter |
| 39 | (result-meanings result)))) |
| 40 | results)) |
| 41 | (results (filter (lambda (result) (not (null? (result-meanings result)))) |
| 42 | results))) |
| 43 | results)) |
| 44 | |
| 45 | (define (compile input meaning-filter output) |
| 46 | (let* ((results (get-results input meaning-filter |
| 47 | (load-frequency "dictionaries/frequency.tsv")))) |
| 48 | (format #t "Number of entries in ~a: ~a~%" output (length results)) |
| 49 | (call-with-output-file output |
| 50 | (lambda (port) |
| 51 | (put-bytevector port |
| 52 | (serialize-dictionary results)))))) |
| 53 | |
| 54 | (define (get-pitch input) |
| 55 | (call-with-input-file input |
| 56 | (lambda (port) |
| 57 | (xml->pitch port)))) |
| 58 | |
| 59 | (define (pitch input output) |
| 60 | (let ((results (get-pitch input))) |
| 61 | (format #t "~a results.~%" (length results)) |
| 62 | (call-with-output-file output |
| 63 | (lambda (port) |
| 64 | (put-bytevector port |
| 65 | (serialize-pitch results)))))) |
| 66 | |
| 67 | (match (command-line) |
| 68 | ((_ cmd input output) |
| 69 | (cond |
| 70 | ((equal? cmd "build") |
| 71 | (compile input (const #t) output)) |
| 72 | ((equal? cmd "pitch") |
| 73 | (pitch input output)) |
| 74 | (else (format #t "Unknown cmd ~a.~%" cmd))))) |
| 75 |