From d1880fada241c00b42f883c3a34e9becaaa64796 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 17 Mar 2006 20:00:42 +0000 Subject: (DICT): Mandatory attribute LANG. (update-stat): Rewrite to match new table structure. (check-node,insert-node): Take destination language code as 3rd argument. All callers changed. git-svn-id: file:///home/puszcza/svnroot/ellinika/trunk@363 941c8c0f-9102-463b-b60b-cd22ce0e6858 --- scm/dictrans.scm | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'scm') diff --git a/scm/dictrans.scm b/scm/dictrans.scm index 39791fd..115ea58 100644 --- a/scm/dictrans.scm +++ b/scm/dictrans.scm @@ -298,7 +298,7 @@ (begin (write node) (newline))) - (set! node-list (cons current-node node-list))) + (set! node-list (cons node node-list))) ;;; Topic stack (define topic-list '()) @@ -334,6 +334,10 @@ (xmltrans:start-tag "DICT" (tag attr) + (let ((lang (xmltrans:attr attr "LANG"))) + (if (not lang) + (xmltrans:parse-error #f "Required attribute LANG not specified")) + (push-node lang)) #f) (xmltrans:end-tag @@ -686,13 +690,18 @@ (current-error-port))))) (define (update-stat conn) - (let ((count (query-number conn "SELECT count(*) from dict"))) - (run-query conn "DELETE from stat"); - (run-query conn - (string-append - "INSERT INTO stat (count,updated) VALUES(" - (number->string count) - ",now())")))) + (run-query conn "DELETE FROM stat") + (for-each + (lambda (res) + (run-query conn + (string-append + "INSERT INTO stat (lang,count,updated) VALUES('" + (list-ref res 0) "'," + (list-ref res 1) + ",now())"))) + (run-query + conn + "SELECT articles.lang,count(distinct dict.word) FROM dict,articles WHERE dict.ident=articles.ident GROUP BY 1"))) ;;; Insert (or update) topics and topic categories (define (insert-categories conn) @@ -732,7 +741,7 @@ ;;; (define dict-index 0) -(define (check-node conn node) +(define (check-node conn node lang) (call-with-current-continuation (lambda (return) (for-each @@ -761,7 +770,7 @@ (node-get #:p-list node)) #t))) -(define (insert-node conn node) +(define (insert-node conn node lang) (letrec ((insert-link (lambda (type value) (run-query conn @@ -853,9 +862,10 @@ (run-query conn (format #f - "INSERT INTO articles VALUES (~A, ~A, \"~A\")" + "INSERT INTO articles VALUES (~A, ~A, '~A', \"~A\")" dict-index article-index + lang text)) (set! article-index (1+ article-index))) (p-article-get #:article p-article))))) @@ -991,12 +1001,20 @@ Informational options: (get-dict-index conn) (insert-categories conn) - - (for-each - (lambda (node) - (and (check-node conn node) - (insert-node conn node))) - (reverse node-list)) + + (let ((lang #f)) + (for-each + (lambda (node) + (cond + ((string? node) + (set! lang node)) + ((vector? node) + (and (check-node conn node lang) + (insert-node conn node lang))) + (else + (display "Unexpected node type!\n") + (exit 1)))) + (reverse node-list))) (pending-fixup conn) (update-stat conn) -- cgit v1.2.1