aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--cgi-bin/Makefile.am3
-rw-r--r--cgi-bin/dico-ellinika.scm4128
3 files changed, 117 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index c19d7f4..b89edeb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-05-30 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * cgi-bin/dico-ellinika.scm4: Implement define, match and
+ output methods.
+
2008-05-29 Sergey Poznyakoff <gray@gnu.org.ua>
* cgi-bin/dico-ellinika.scm4: New file. A database driver for
diff --git a/cgi-bin/Makefile.am b/cgi-bin/Makefile.am
index 0df6955..1a7fd96 100644
--- a/cgi-bin/Makefile.am
+++ b/cgi-bin/Makefile.am
@@ -1,5 +1,5 @@
# This file is part of Ellinika project.
-# Copyright (C) 2004, 2005, 2007 Sergey Poznyakoff
+# Copyright (C) 2004, 2005, 2007, 2008 Sergey Poznyakoff
#
# Ellinika is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
cgidir=@CGIDIR@
cgi_SCRIPTS=$(EXTRA_DIST:.scm4=.@SCRIPT_SUFFIX@)
+EXTRA_SCRIPTS=dico-ellinika.scm
EXTRA_DIST=dict.scm4 nea.scm4
CLEANFILES=dict.m4 dict.scm nea.scm dict.cgi nea.cgi
diff --git a/cgi-bin/dico-ellinika.scm4 b/cgi-bin/dico-ellinika.scm4
index 1c3945d..b2eabf3 100644
--- a/cgi-bin/dico-ellinika.scm4
+++ b/cgi-bin/dico-ellinika.scm4
@@ -99,7 +99,7 @@
(sql-query db-connection "SET NAMES utf8")
db-connection))
-(define (close-module dbh)
+(define (close-module name dbh)
(sql-connect-close dbh))
(define (descr name handle)
@@ -115,29 +115,121 @@ any later version published by the Free Software Foundation; with no\n\
Invariant Sections, no Front-Cover and Back-Cover Texts"))
(define (define-word name dbh word)
- (let* ((key (ellinika:translate-input word))
- (result (my-sql-query
- dbh
- (string-append
- "SELECT dict.word,dict.ident,pos.abbr,dict.forms,articles.subindex,articles.meaning "
- "FROM dict,articles,pos WHERE dict.word=\""
- key
- "\" AND dict.ident=articles.ident "
- "AND articles.lang='" target-language "' "
- "AND dict.pos=pos.id AND pos.canonical='Y' ORDER BY dict.ident, articles.subindex"))))
- result))
+ (let ((key (ellinika:translate-input word)))
+ (let ((result '())
+ (last-id -1)
+ (word '())
+ (articles '()))
+ (for-each
+ (lambda (tuple)
+ (cond
+ ((not (= last-id (string->number (car tuple))))
+ (if (not (null? articles))
+ (set! result (cons
+ (cons word (reverse articles))
+ result)))
+ (set! last-id (string->number (car tuple)))
+ (set! word (cons (list-ref tuple 1)
+ (list-ref tuple 2))); FIXME: forms?
+ (set! articles '())))
+ (set! articles (cons
+ (cons (list-ref tuple 4)
+ (list-ref tuple 5))
+ articles)))
+ (my-sql-query
+ dbh
+ (string-append
+ "SELECT dict.ident,dict.word,pos.abbr,dict.forms,articles.subindex,articles.meaning "
+ "FROM dict,articles,pos WHERE dict.word=\""
+ key
+ "\" AND dict.ident=articles.ident "
+ "AND articles.lang='" target-language "' "
+ "AND dict.pos=pos.id AND pos.canonical='Y' ORDER BY dict.ident, articles.subindex")))
+ (if (not (null? articles))
+ (set! result (cons
+ (cons word (reverse articles))
+ result)))
+ (cons #t (reverse result)))))
+
+(define (match-exact dbh strat word)
+ (my-sql-query
+ dbh
+ (string-append "SELECT DISTINCT word FROM dict WHERE word=\""
+ (ellinika:translate-input word)
+ "\" ORDER BY 1")))
+
+(define (match-prefix dbh strat word)
+ (my-sql-query
+ dbh
+ (string-append "SELECT DISTINCT word FROM dict WHERE word LIKE \""
+ (ellinika:translate-input word)
+ "%\" ORDER BY 1")))
+
+(define (match-suffix dbh strat word)
+ (my-sql-query
+ dbh
+ (string-append "SELECT DISTINCT word FROM dict WHERE word LIKE \"%"
+ (ellinika:translate-input word)
+ "\" ORDER BY 1")))
+
+(define (match-extnd-regex dbh strat word)
+ (my-sql-query
+ dbh
+ (string-append "SELECT DISTINCT word FROM dict WHERE word regexp \""
+ (ellinika:translate-input word)
+ "\" ORDER BY 1")))
+
+(define (match-basic-regex dbh strat word)
+ #f) ;FIXME
+
+(define (match-default dbh strat word)
+ (my-sql-query
+ dbh
+ (string-append "SELECT DISTINCT word FROM dict WHERE sound LIKE \""
+ (ellinika:sounds-like word)
+ "%\"")))
+
+
+(define strategy-list
+ (list (cons "exact" match-exact)
+ (cons "prefix" match-prefix)
+ (cons "suffix" match-suffix)
+ (cons "re" match-extnd-regex)
+ (cons "regexp" match-basic-regex)))
(define (match-word name dbh strat word)
- #f)
+ (let ((sp (assoc (dico-strat-name strat) strategy-list)))
+ (let ((res (if sp
+ ((cdr sp) dbh strat word)
+ (match-default dbh strat word))))
+ (if res
+ (cons #f (map car res))
+ #f))))
(define (output res n)
- (let ((x (list-ref res n)))
- (if x
- (display x))
- (newline)))
+ (let ((type (car res))
+ (contents (list-ref (cdr res) n)))
+ (cond
+ (type
+ (let ((word-pair (car contents))
+ (defn (cdr contents)))
+ (display (car word-pair))
+ (display ", <")
+ (display (cdr word-pair))
+ (display ">")
+ (for-each
+ (lambda (article)
+ (newline)
+ (display (1+ (string->number (car article))))
+ (display ". ")
+ (display (cdr article))
+ (display ";"))
+ defn)))
+ (else
+ (display contents)))))
(define (result-count res)
- (length res))
+ (length (cdr res)))
;;
;; Setup

Return to:

Send suggestions and report system problems to the System administrator.