diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-06-14 14:20:39 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-06-14 14:20:39 +0300 |
commit | 8c1de36d1f8b27fb946dac15e725c93ec57c1538 (patch) | |
tree | 17babe745cf794a7485fc2bc0b9c9e0c9120d893 /src/ellinika | |
parent | ce29f168ed52f08228b99a789785271a4a3c9b0e (diff) | |
download | ellinika-8c1de36d1f8b27fb946dac15e725c93ec57c1538.tar.gz ellinika-8c1de36d1f8b27fb946dac15e725c93ec57c1538.tar.bz2 |
Improve SQL interface.
* src/ellinika/sql.scm (ellinika:sql-verbose)
(ellinika:sql-dry-run,ellinika:sql-conn): New public vars.
(ellinika:format-sql-query): New function.
(ellinika:sql-query): Rewrite.
* scm/verbop.scm: Use (ellinika sql).
* src/ellinika/conjugator.scm: Likewise.
* src/ellinika/test-conjugation.scm: Likewise.
* data/irregular-verbs.xml: Update.
* src/ellinika/tests/conj/apomenv.scm: New file.
Diffstat (limited to 'src/ellinika')
-rw-r--r-- | src/ellinika/conjugator.scm | 106 | ||||
-rw-r--r-- | src/ellinika/sql.scm | 116 | ||||
-rw-r--r-- | src/ellinika/test-conjugation.scm | 8 | ||||
-rw-r--r-- | src/ellinika/tests/conj/apomenv.scm | 4 | ||||
-rw-r--r-- | src/ellinika/tests/conj/blepv.scm | 1 |
5 files changed, 151 insertions, 84 deletions
diff --git a/src/ellinika/conjugator.scm b/src/ellinika/conjugator.scm index 25ae255..0079d12 100644 --- a/src/ellinika/conjugator.scm +++ b/src/ellinika/conjugator.scm | |||
@@ -1,4 +1,4 @@ | |||
1 | ;;;; Modern Greek Verb Conjugator. | 1 | ;;;; Verb Conjugator for modern Greek (δημοτική). |
2 | ;;;; This file is part of Ellinika project. | 2 | ;;;; This file is part of Ellinika project. |
3 | ;;;; Copyright (C) 2011 Sergey Poznyakoff | 3 | ;;;; Copyright (C) 2011 Sergey Poznyakoff |
4 | ;;;; | 4 | ;;;; |
@@ -21,15 +21,10 @@ | |||
21 | (ellinika elmorph) | 21 | (ellinika elmorph) |
22 | (ellinika i18n) | 22 | (ellinika i18n) |
23 | (ellinika tenses) | 23 | (ellinika tenses) |
24 | (gamma sql)) | 24 | (ellinika sql)) |
25 | 25 | ||
26 | (use-syntax (ice-9 syncase)) | 26 | (use-syntax (ice-9 syncase)) |
27 | 27 | ||
28 | (define (my-sql-query conn query) | ||
29 | ; (format #t "Q: ~A~%" query) | ||
30 | (let ((res (sql-query conn query))) | ||
31 | ; (format #t "R: ~A~%" res) | ||
32 | res)) | ||
33 | 28 | ||
34 | ;; Verb info | 29 | ;; Verb info |
35 | ;; #:verb - Verb in dictionary form | 30 | ;; #:verb - Verb in dictionary form |
@@ -80,36 +75,33 @@ | |||
80 | ;; FIXME: deponentia? | 75 | ;; FIXME: deponentia? |
81 | (else "A"))) | 76 | (else "A"))) |
82 | 77 | ||
83 | (define (create-basic-verb-info conn verb proplist . rest) | 78 | (define (create-basic-verb-info verb proplist . rest) |
84 | ; (format #t "PROPLIST ~A~%" proplist) | 79 | ; (format #t "PROPLIST ~A~%" proplist) |
85 | (let ((class (if (null? rest) | 80 | (let ((class (if (null? rest) |
86 | "" | 81 | "" |
87 | (string-append " AND conj='" (car rest) "'")))) | 82 | (string-append |
88 | (let ((vdb (my-sql-query | 83 | " AND conj=\"" (utf8-escape (car rest)) "\"")))) |
89 | conn | 84 | (let ((vdb (ellinika:sql-query |
90 | (string-append | 85 | "SELECT conj FROM verbclass WHERE verb=\"~A\"~A" |
91 | "SELECT conj FROM verbclass WHERE verb='" (force-string verb) "'" | 86 | verb class))) |
92 | class)))) | ||
93 | (cond | 87 | (cond |
94 | ((and vdb (not (null? vdb)));FIXME | 88 | ((and vdb (not (null? vdb))) |
95 | (list (caar vdb) verb proplist '(class))) | 89 | (list (caar vdb) verb proplist '(class))) |
96 | ((elstr-suffix? verb "άω") | 90 | ((elstr-suffix? verb "άω") |
97 | (create-basic-verb-info conn (elstr-append | 91 | (create-basic-verb-info (elstr-append |
98 | (elstr-trim verb -2) "ώ") "B1")) | 92 | (elstr-trim verb -2) "ώ") "B1")) |
99 | ((null? rest) | 93 | ((null? rest) |
100 | (list (guess-verb-class verb) verb proplist '())) | 94 | (list (guess-verb-class verb) verb proplist '())) |
101 | (else | 95 | (else |
102 | (list (car rest) verb '() '())))))) | 96 | (list (car rest) verb '() '())))))) |
103 | 97 | ||
104 | (define (load-verb-info conn verb voice mood tense) | 98 | (define (load-verb-info verb voice mood tense) |
105 | ; (format #t "LOAD ~A~%" verb) | 99 | ; (format #t "LOAD ~A~%" verb) |
106 | (let ((verbprop (my-sql-query | 100 | (let ((verbprop (ellinika:sql-query |
107 | conn | 101 | "SELECT property,value FROM verbtense WHERE \ |
108 | (string-append | 102 | verb=\"~A\" AND voice=\"~A\" AND mood=\"~A\" AND tense=\"~A\"" |
109 | "SELECT property,value FROM verbtense WHERE " | 103 | verb voice mood tense))) |
110 | "verb=\"" verb "\" AND voice=\"" voice | 104 | (create-basic-verb-info verb |
111 | "\" AND mood=\"" mood "\" AND tense=\"" tense "\"")))) | ||
112 | (create-basic-verb-info conn verb | ||
113 | (if (null? verbprop) | 105 | (if (null? verbprop) |
114 | '() | 106 | '() |
115 | (map | 107 | (map |
@@ -173,12 +165,11 @@ | |||
173 | (else | 165 | (else |
174 | (elstr-append root "ηθ"))))) | 166 | (elstr-append root "ηθ"))))) |
175 | 167 | ||
176 | (define (lookup-verb-info conn verb voice thema) | 168 | (define (lookup-verb-info verb voice thema) |
177 | (my-sql-query | 169 | (ellinika:sql-query |
178 | conn | 170 | "SELECT root FROM irregular_root \ |
179 | (string-append | 171 | WHERE verb=\"~A\" AND voice=\"~A\" AND thema=\"~A\"" |
180 | "SELECT root FROM irregular_root \ | 172 | verb voice thema)) |
181 | WHERE verb='" verb "' AND voice='" voice "' AND thema='" thema "'"))) | ||
182 | 173 | ||
183 | (define (verb-A-root verb) | 174 | (define (verb-A-root verb) |
184 | (cond | 175 | (cond |
@@ -189,12 +180,12 @@ WHERE verb='" verb "' AND voice='" voice "' AND thema='" thema "'"))) | |||
189 | (else | 180 | (else |
190 | (error "cannot handle ~A~%" verb)))) | 181 | (error "cannot handle ~A~%" verb)))) |
191 | 182 | ||
192 | (define (complement-verb-info conn vinfo verb voice thema) | 183 | (define (complement-verb-info vinfo verb voice thema) |
193 | ; (format #t "COMPLEMENT ~A~%" thema) | 184 | ; (format #t "COMPLEMENT ~A~%" thema) |
194 | (let ((elverb (string->elstr verb)) | 185 | (let ((elverb (string->elstr verb)) |
195 | (result (let ((tmpres (lookup-verb-info conn verb voice thema))) | 186 | (result (let ((tmpres (lookup-verb-info verb voice thema))) |
196 | (if (and (null? tmpres) (string=? thema "sub")) | 187 | (if (and (null? tmpres) (string=? thema "sub")) |
197 | (lookup-verb-info conn verb voice "aor") | 188 | (lookup-verb-info verb voice "aor") |
198 | tmpres)))) | 189 | tmpres)))) |
199 | (verb-set! vinfo #:root | 190 | (verb-set! vinfo #:root |
200 | (cond | 191 | (cond |
@@ -235,7 +226,7 @@ WHERE verb='" verb "' AND voice='" voice "' AND thema='" thema "'"))) | |||
235 | (thema-aoristoy-mesapathitikis-B | 226 | (thema-aoristoy-mesapathitikis-B |
236 | root | 227 | root |
237 | (list-ref | 228 | (list-ref |
238 | (conjugate conn verb "act" "ind" "Αόριστος") | 229 | (conjugate verb "act" "ind" "Αόριστος") |
239 | 0))) | 230 | 0))) |
240 | (else | 231 | (else |
241 | #f)))) | 232 | #f)))) |
@@ -292,15 +283,15 @@ WHERE verb='" verb "' AND voice='" voice "' AND thema='" thema "'"))) | |||
292 | ((conj-info-set! #:accmap v) | 283 | ((conj-info-set! #:accmap v) |
293 | (list-set! v 2 val)) )) | 284 | (list-set! v 2 val)) )) |
294 | 285 | ||
295 | (define (get-conj-info conn conj voice mood tense) | 286 | (define (get-conj-info conj voice mood tense) |
296 | (let ((answer (my-sql-query | 287 | (let ((answer (ellinika:sql-query |
297 | conn | ||
298 | (string-append | ||
299 | "SELECT c.thema,c.suffix,c.accmap,c.particle,c.aux,c.auxtense,c.fold AS fold,\ | 288 | "SELECT c.thema,c.suffix,c.accmap,c.particle,c.aux,c.auxtense,c.fold AS fold,\ |
300 | f.sing1,f.sing2,f.sing3,f.plur1,f.plur2,f.plur3 \ | 289 | f.sing1,f.sing2,f.sing3,f.plur1,f.plur2,f.plur3 \ |
301 | FROM conjugation c, verbflect f \ | 290 | FROM conjugation c, verbflect f \ |
302 | WHERE c.conj='" conj "' AND c.voice='" voice "' AND c.mood='" mood | 291 | WHERE c.conj=\"~A\" AND c.voice=\"~A\" AND c.mood=\"~A\" \ |
303 | "' AND c.tense='" tense "' AND c.flect = f.ident ORDER by fold")))) | 292 | AND c.tense=\"~A\" AND c.flect = f.ident ORDER by fold" |
293 | conj voice mood tense))) | ||
294 | |||
304 | (if (null? answer) | 295 | (if (null? answer) |
305 | #f | 296 | #f |
306 | answer))) | 297 | answer))) |
@@ -439,14 +430,13 @@ WHERE c.conj='" conj "' AND c.voice='" voice "' AND c.mood='" mood | |||
439 | forms) | 430 | forms) |
440 | (map force-string forms))))) | 431 | (map force-string forms))))) |
441 | 432 | ||
442 | (define (individual-verb conn verb voice mood tense) | 433 | (define (individual-verb verb voice mood tense) |
443 | (let ((res (my-sql-query | 434 | (let ((res (ellinika:sql-query |
444 | conn | 435 | "SELECT f.sing1,f.sing2,f.sing3,f.plur1,f.plur2,f.plur3 \ |
445 | (string-append | ||
446 | "SELECT f.sing1,f.sing2,f.sing3,f.plur1,f.plur2,f.plur3 \ | ||
447 | FROM individual_verb i,verbflect f \ | 436 | FROM individual_verb i,verbflect f \ |
448 | WHERE i.verb='" verb "' AND i.voice='" voice "' AND i.mood='" mood | 437 | WHERE i.verb=\"~A\" AND i.voice=\"~A\" AND i.mood=\"~A\"\ |
449 | "' AND i.tense = '" tense "' AND i.ident=f.ident")))) | 438 | AND i.tense=\"~A\" AND i.ident=f.ident" |
439 | verb voice mood tense))) | ||
450 | (if (not (null? res)) | 440 | (if (not (null? res)) |
451 | (append (car res) | 441 | (append (car res) |
452 | (list "I" | 442 | (list "I" |
@@ -459,15 +449,14 @@ WHERE i.verb='" verb "' AND i.voice='" voice "' AND i.mood='" mood | |||
459 | (or a b)) | 449 | (or a b)) |
460 | lista listb)) | 450 | lista listb)) |
461 | 451 | ||
462 | (define (conjugate conn verb voice mood tense . rest) | 452 | (define (conjugate verb voice mood tense . rest) |
463 | (cond | 453 | (cond |
464 | ((individual-verb conn verb voice mood tense) => | 454 | ((individual-verb verb voice mood tense) => |
465 | (lambda (res) | 455 | (lambda (res) |
466 | (list res))) | 456 | (list res))) |
467 | (else | 457 | (else |
468 | (let* ((vinfo (load-verb-info conn verb voice mood tense)) | 458 | (let* ((vinfo (load-verb-info verb voice mood tense)) |
469 | (conj-list (get-conj-info conn | 459 | (conj-list (get-conj-info (verb-get vinfo #:conj) |
470 | (verb-get vinfo #:conj) | ||
471 | voice mood tense))) | 460 | voice mood tense))) |
472 | (if (not conj-list) | 461 | (if (not conj-list) |
473 | (list (list #f #f #f #f #f #f) #f #f) | 462 | (list (list #f #f #f #f #f #f) #f #f) |
@@ -496,7 +485,7 @@ WHERE i.verb='" verb "' AND i.voice='" voice "' AND i.mood='" mood | |||
496 | (cond | 485 | (cond |
497 | ((string=? (conj-info #:thema conj) "synt") | 486 | ((string=? (conj-info #:thema conj) "synt") |
498 | (let* ((verb-conj | 487 | (let* ((verb-conj |
499 | (car (conjugate conn verb voice "sub" "Αόριστος" | 488 | (car (conjugate verb voice "sub" "Αόριστος" |
500 |