;;; Nani Project website ;;; Copyright © 2019 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 jmdict trie)) (use-modules (nani jmdict serialize)) (use-modules (nani jmdict xml)) (use-modules (nani frequency)) (use-modules (nani trie)) (use-modules (nani result)) (use-modules (ice-9 match)) (use-modules (ice-9 binary-ports)) (define (convert input output) (let ((sxml (load-dic input))) (call-with-output-file output (lambda (port) (write sxml port))))) ;; 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 sense-filter frq) (let* ((results (get-results1 input frq)) (results (map (lambda (result) (update-result result #:senses (filter sense-filter (result-senses result)))) results)) (results (filter (lambda (result) (not (null? (result-senses result)))) results))) results)) (define (compile input sense-filter output) (let* ((results (get-results input sense-filter (load-frequency "dictionaries/frequency.tsv"))) (kanji-trie (compress-trie (make-kanji-trie results))) (reading-trie (compress-trie (make-reading-trie results))) (meaning-trie (compress-trie (make-meaning-trie results)))) (format #t "Number of entries in ~a: ~a~%" output (length results)) (call-with-output-file output (lambda (port) (put-bytevector port (serialize-jmdict results kanji-trie reading-trie meaning-trie)))))) (define (print word dict) #t) (match (command-line) ((_ cmd input lang output) (cond ((equal? cmd "build") (if (equal? lang "e") (compile input (const #t) output) (compile input (lambda (sense) (equal? (sense-language sense) lang)) output))) ((equal? cmd "convert") (convert input output)) (else (format #t "Unknown cmd ~a.~%" cmd)))) ((_ "print" word input) (print word input)))