;;; Nani Project website ;;; Copyright © 2020 Julien Lepiller ;;; ;;; This file is part of the Nani Project website. ;;; ;;; The Nani Project website is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU Affero General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; The Nani Project website is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU Affero General Public License for more details. ;;; ;;; You should have received a copy of the GNU Affero General Public License ;;; along with the Nani Project website. If not, see . (use-modules (nani pitch wadoku)) (use-modules (nani pitch pitch)) (use-modules (nani result frequency)) (use-modules (nani result result)) (use-modules (nani result wadoku)) (use-modules (ice-9 match)) (use-modules (ice-9 binary-ports)) ;; Break these steps to try and let the GC reclaim these big objects (define (get-results1 input frq) (call-with-input-file input (lambda (port) (xml->results port frq)))) (define (get-results input meaning-filter frq) (let* ((results (get-results1 input frq)) (results (map (lambda (result) (update-result result #:meanings (filter meaning-filter (result-meanings result)))) results)) (results (filter (lambda (result) (not (null? (result-meanings result)))) results))) results)) (define (compile input meaning-filter output) (let* ((results (get-results input meaning-filter (load-frequency "dictionaries/frequency.tsv")))) (format #t "Number of entries in ~a: ~a~%" output (length results)) (call-with-output-file output (lambda (port) (put-bytevector port (serialize-dictionary results)))))) (define (get-pitch input) (call-with-input-file input (lambda (port) (xml->pitch port)))) (define (pitch input output) (let ((results (get-pitch input))) (format #t "~a results.~%" (length results)) (call-with-output-file output (lambda (port) (put-bytevector port (serialize-pitch results)))))) (match (command-line) ((_ cmd input output) (cond ((equal? cmd "build") (compile input (const #t) output)) ((equal? cmd "pitch") (pitch input output)) (else (format #t "Unknown cmd ~a.~%" cmd)))))