summaryrefslogtreecommitdiffabout
path: root/src/ellinika/conjugator.scm
Side-by-side diff
Diffstat (limited to 'src/ellinika/conjugator.scm') (more/less context) (ignore whitespace changes)
-rw-r--r--src/ellinika/conjugator.scm354
1 files changed, 189 insertions, 165 deletions
diff --git a/src/ellinika/conjugator.scm b/src/ellinika/conjugator.scm
index bffc6be..eae4ad0 100644
--- a/src/ellinika/conjugator.scm
+++ b/src/ellinika/conjugator.scm
@@ -37,7 +37,7 @@
;; properties - associative list of properties
;; attested
-(define (verb-set! verb key value)
+(define (vinfo-set! verb key value)
; (format #t "VERB ~A KEY ~A VALUE ~A~%" verb key value)
(case key
((#:conj)
@@ -60,7 +60,7 @@
(cons key value)))))))))
-(define (verb-get verb key)
+(define (vinfo-get verb key)
(case key
((#:conj)
(list-ref verb 0))
@@ -103,8 +103,8 @@
(let ((verbprop (ellinika:sql-query
"SELECT property,value FROM verbtense WHERE \
verb=\"~A\" AND voice=\"~A\" AND mood=\"~A\" AND tense=\"~A\""
- (verb-get vinfo #:verb) voice mood tense)))
- (verb-set!
+ (vinfo-get vinfo #:verb) voice mood tense)))
+ (vinfo-set!
vinfo #:proplist
(let loop ((inlist (if (null? verbprop)
'()
@@ -194,6 +194,11 @@ verb=\"~A\" AND voice=\"~A\" AND mood=\"~A\" AND tense=\"~A\""
(else
(elstr-append stem "ηθ")))))
+(define (thema-aoristou-prostaktikhs stem)
+ (if (elstr-suffix? stem "β" "γ" "θ" "ν")
+ (elstr-append stem "ε")
+ stem))
+
(define (lookup-verb-info verb voice thema)
(ellinika:sql-query
"SELECT stem FROM irregular_stem \
@@ -210,6 +215,7 @@ WHERE verb=\"~A\" AND voice=\"~A\" AND thema=\"~A\""
(throw 'conjugator-error 'conjugator-error-input
"cannot handle ~A" (list (force-string verb))))))
+;; FIXME: Use vinfo #:verb instead of the verb argument.
(define (complement-verb-info vinfo verb voice thema)
; (format #t "COMPLEMENT ~A~%" vinfo)
(let ((elverb (string->elstr verb))
@@ -217,53 +223,58 @@ WHERE verb=\"~A\" AND voice=\"~A\" AND thema=\"~A\""
(if (and (null? tmpres) (string=? thema "sub"))
(lookup-verb-info verb voice "aor")
tmpres))))
- (verb-set! vinfo #:stem
+ (vinfo-set! vinfo #:stem
(cond
((not (null? result))
- (verb-set! vinfo #:attested 'stem)
+ (vinfo-set! vinfo #:attested 'stem)
(map car result))
- ((string=? (verb-get vinfo #:conj) "A")
+ ((string=? (vinfo-get vinfo #:conj) "A")
(let ((stem (verb-A-stem elverb)))
(cond
((string=? thema "pres")
- (verb-set! vinfo #:attested 'stem)
+ (vinfo-set! vinfo #:attested 'stem)
stem)
((or (string=? thema "aor") (string=? thema "sub"))
- (if (string=? voice "act")
- (elstr-thema-aoristoy stem)
- (thema-aoristoy-mesapathitikis-A stem)))
+ (cond
+ ((string=? voice "act")
+ (elstr-thema-aoristoy stem))
+ ((string=? voice "pas")
+ (thema-aoristoy-mesapathitikis-A stem))
+ (else
+ (throw 'conjugator-error 'conjugator-error-db
+ "invalid voice ~A" (list voice)))))
(else
#f))))
- ((string=? (verb-get vinfo #:conj) "A-depon")
+ ((string=? (vinfo-get vinfo #:conj) "A-depon")
(let ((stem (verb-A-stem elverb)))
(cond
((string=? thema "pres")
- (verb-set! vinfo #:attested 'stem)
+ (vinfo-set! vinfo #:attested 'stem)
stem)
((or (string=? thema "aor") (string=? thema "sub"))
#f) ; FIXME
(else
#f))))
- ((string=? (verb-get vinfo #:conj) "B1")
+ ((string=? (vinfo-get vinfo #:conj) "B1")
(let ((stem (if (elstr-suffix? elverb "άω")
(elstr-trim elverb -2)
(elstr-trim elverb -1))))
(cond
((or (string=? voice "act") (string=? thema "pres"))
- (verb-set! vinfo #:attested 'stem)
+ (vinfo-set! vinfo #:attested 'stem)
stem)
((or (string=? thema "aor") (string=? thema "sub"))
(map
(lambda (aor)
(thema-aoristoy-mesapathitikis-B stem aor))
- (conjugate verb "act" "ind" "Αόριστος")))
+ (conjugate vinfo "act" "ind" "Αόριστος")))
(else
#f))))
- ((string=? (verb-get vinfo #:conj) "B2")
+ ((string=? (vinfo-get vinfo #:conj) "B2")
(let ((stem (elstr-trim elverb -1)))
(cond
((or (string=? voice "act") (string=? thema "pres"))
- (verb-set! vinfo #:attested 'stem)
+ (vinfo-set! vinfo #:attested 'stem)
stem)
((or (string=? thema "aor") (string=? thema "sub"))
(elstr-append stem "ηθ")) ;; FIXME: guesswork
@@ -343,7 +354,7 @@ AND c.tense=\"~A\" AND c.flect = f.ident ORDER by fold"
(+ (- len syl) 1))))
;; (define (get-property conj vinfo key default)
-;; (if ((override (verb-get vinfo
+;; (if ((override (vinfo-get vinfo
;; (symbol->keyword
;; (string->symbol
;; (string-append
@@ -352,37 +363,37 @@ AND c.tense=\"~A\" AND c.flect = f.ident ORDER by fold"
;; (if override
;; (let ((t (conj-info key conj)))
;; (if t
-;; (or (verb-get vinfo key)
+;; (or (vinfo-get vinfo key)
;; t)
-;; (or (verb-get vinfo key)
+;; (or (vinfo-get vinfo key)
;; (conj-info key conj)
;; default))))))
(define (get-suffix conj vinfo)
- (let ((ret (let ((override (verb-get vinfo #:override)))
+ (let ((ret (let ((override (vinfo-get vinfo #:override)))
(if (and override
(member "suffix" override))
(let ((t (conj-info #:suffix conj)))
(if t
- (or (verb-get vinfo #:suffix)
+ (or (vinfo-get vinfo #:suffix)
t)
""))
- (or (verb-get vinfo #:suffix)
+ (or (vinfo-get vinfo #:suffix)
(conj-info #:suffix conj)
"")))))
(if (list? ret) ret (list ret))))
(define (get-accmap conj vinfo)
- (let ((override (verb-get vinfo #:override)))
+ (let ((override (vinfo-get vinfo #:override)))
(if (and override
(member "accmap" override))
(let ((t (conj-info #:accmap conj)))
(if t
- (or (verb-get vinfo #:accmap)
+ (or (vinfo-get vinfo #:accmap)
t)))
- (or (verb-get vinfo #:accmap)
+ (or (vinfo-get vinfo #:accmap)
(conj-info #:accmap conj)
"000000"))))
@@ -394,13 +405,13 @@ AND c.tense=\"~A\" AND c.flect = f.ident ORDER by fold"
(cond
((> (length accmap) 6)
(set! accmap (list-head accmap 6))
- (set! augment (or (verb-get vinfo #:augment) "ε"))))
-; (format #t "AUGMENT ~A ~A~%" vinfo (verb-get vinfo #:augment))
+ (set! augment (or (vinfo-get vinfo #:augment) "ε"))))
+; (format #t "AUGMENT ~A ~A~%" vinfo (vinfo-get vinfo #:augment))
(let ((forms
(map
(lambda (flect acc person)
(cond
- ((verb-get vinfo (symbol->keyword
+ ((vinfo-get vinfo (symbol->keyword
(string->symbol
(number->string person)))) =>
(lambda (personal-form)
@@ -468,18 +479,22 @@ AND c.tense=\"~A\" AND c.flect = f.ident ORDER by fold"
forms)
(map force-string forms)))))
-(define (individual-verb verb voice mood tense)
+(define (individual-verb vinfo voice mood tense)
(let ((res (ellinika:sql-query
"SELECT f.sing1,f.sing2,f.sing3,f.plur1,f.plur2,f.plur3\
FROM individual_verb i,verbflect f\
WHERE i.verb=\"~A\" AND i.voice=\"~A\" AND i.mood=\"~A\"\
AND i.tense=\"~A\" AND i.ident=f.ident"
- verb voice mood tense)))
- (if (not (null? res))
- (append (car res)
- (list "I"
- '(class stem)))
- #f)))
+ (vinfo-get vinfo #:verb) voice mood tense)))
+ (if (null? res)
+ #f
+ (map
+ (lambda (elt)
+ (append
+ elt
+ (list "I"
+ '(class stem))))
+ res))))
(define (merge-conjugated-forms lista listb)
(map
@@ -487,141 +502,150 @@ AND c.tense=\"~A\" AND c.flect = f.ident ORDER by fold"
(or a b))
lista listb))
-(define (conjugate verb voice mood tense . rest)
+(define (conjugate vinfo voice mood tense . rest)
(cond
- ((individual-verb verb voice mood tense) =>
+ ((individual-verb vinfo voice mood tense) =>
(lambda (res)
- (list res)))
+ res))
(else
- (let* ((vinfo (load-verb-info verb voice mood tense))
- (conj-list (get-conj-info (or
- (verb-get vinfo #:class)
- (verb-get vinfo #:conj))
- voice mood tense))
- (verb (force-string (verb-get vinfo #:verb))))
- (format #t "VINFO ~A~%" vinfo)
- (if (not conj-list)
- (list (list #f #f #f #f #f #f #f #f))
- (map car
- (fold
- (lambda (elt prev)
-; (format #t "ELT ~A~%" elt)
- (if (null? prev)
- (list elt)
- (let ((top (car prev)))
- (if (let ((a (cdr elt))
- (b (cdr top)))
- (and (string? a) (string? b) (string=? a b)))
- (cons (cons
- (merge-conjugated-forms (car top) (car elt))
- (cdr top))
- (cdr prev))
- (cons elt prev)))))
- '()
- (fold
- (lambda (conj prev)
+ (let ((vinfo (copy-tree vinfo)))
+ (if (not (member #:noload rest))
+ (load-proplist vinfo voice mood tense))
+; (format #t "VINFO ~A~%" vinfo)
+ (let ((conj-list (get-conj-info (or
+ (vinfo-get vinfo #:class)
+ (vinfo-get vinfo #:conj))
+ voice mood tense))
+ (verb (force-string (vinfo-get vinfo #:verb))))
+; (format #t "VINFO ~A~%" vinfo)
+ (if (not conj-list)
+ (list (list #f #f #f #f #f #f #f #f))
+ (map car
+ (fold
+ (lambda (elt prev)
+; (format #t "ELT ~A~%" elt)
+ (if (null? prev)
+ (list elt)
+ (let ((top (car prev)))
+ (if (let ((a (cdr elt))
+ (b (cdr top)))
+ (and (string? a) (string? b) (string=? a b)))
+ (cons (cons
+ (merge-conjugated-forms (car top) (car elt))
+ (cdr top))
+ (cdr prev))
+ (cons elt prev)))))
+ '()
+ (fold
+ (lambda (conj prev)
; (format #t "CONJ ~A~%" conj)
- (if (member #:nopart rest)
- (conj-info-set! #:particle conj #f))
- (cond
- ((and (string=? (conj-info #:thema conj) "synt")
- (conj-info #:aux conj))
- (let ((aparemfato-list
- (map
- (lambda (x)
- (let ((t (conjugation:table x)))
- (if t
+ (if (member #:nopart rest)
+ (conj-info-set! #:particle conj #f))
+ (cond
+ ((and (string=? (conj-info #:thema conj) "synt")
+ (conj-info #:aux conj))
+ (let ((aparemfato-list
+ (map
+ (lambda (x)
+ (let ((t (conjugation:table x)))
+ (if t
+ (cons
+ (list-ref t 2)
+ (conjugation:attested x))
+ #f)))
+ (conjugate vinfo voice "sub" "Αόριστος"
+ #:nopart)))
+ (part (conj-info #:particle conj))
+ (fold-id (conj-info #:fold conj)))
+ (fold
+ (lambda (param prev)
+ (if (not param)
+ prev
+ (let ((aparemfato (car param))
+ (attested (cdr param)))
+ (cons
(cons
- (list-ref t 2)
- (conjugation:attested x))
- #f)))
- (conjugate verb voice "sub" "Αόριστος"
- #:nopart)))
- (part (conj-info #:particle conj))
- (fold-id (conj-info #:fold conj)))
- (fold
- (lambda (param prev)
- (if (not param)
- prev
- (let ((aparemfato (car param))
- (attested (cdr param)))
- (cons
- (cons
- (append
- (map
- (lambda (aux flag)
- (if (char=? flag #\-)
- #f
- (elstr->string
- (if part
- (elstr-append part " " aux " "
- aparemfato)
- (elstr-append aux " " aparemfato)))))
- (conjugation:table
- (car (conjugate (conj-info #:aux conj)
- "act" "ind"
- (conj-info #:auxtense conj))))
- (string->list (or (verb-get vinfo #:accmap)
- (conj-info #:accmap conj)
- "000000")))
- (list (verb-get vinfo #:conj)
- attested))
- fold-id)
- prev))))
- prev
- aparemfato-list)))
- ((and (string=? (conj-info #:thema conj) "synt")
- (conj-info #:auxtense conj))
- (let ((part (conj-info #:particle conj)))
- (fold-right
- (lambda (tenses prev)
- (cons
- (cons
- (append
- (map
- (lambda (t)
- (elstr->string (elstr-append part " " t)))
- (list-head tenses 6))
- (list-tail tenses 6))
- (conj-info #:fold conj))
- prev))
- prev
- (conjugate verb voice "ind"
- (conj-info #:auxtense conj)))))
- (else
- (let ((vinfo (copy-tree vinfo)))
- (if (verb-get vinfo #:stem)
- (verb-set! vinfo #:attested 'stem)
- (let ((thema (string-split (conj-info #:thema conj) #\:)))
-; (format #t "THEMA ~A~%" thema)
- (complement-verb-info vinfo verb
- (if (null? (cdr thema))
- voice
- (car (cdr thema)))
- (car thema))))
-
- (fold
- (lambda (suffix prev)
- (append
- (fold
- (lambda (stem prev)
- (cons
- (cons
- (append (apply-flect conj vinfo verb stem suffix)
- (list (verb-get vinfo #:conj)
- (verb-get vinfo #:attested)))
- (conj-info #:fold conj))
- prev))
- '()
- (verb-get vinfo #:stem))
- prev))
- prev
- (get-suffix conj vinfo))))))
- '()
- conj-list))))))))
+ (append
+ (map
+ (lambda (aux flag)
+ (if (char=? flag #\-)
+ #f
+ (elstr->string
+ (if part
+ (elstr-append part " " aux " "
+ aparemfato)
+ (elstr-append aux " " aparemfato)))))
+ (conjugation:table
+ (car (conjugate
+ (conjugator:open-verb
+ (conj-info #:aux conj))
+ "act" "ind"
+ (conj-info #:auxtense conj))))
+ (string->list (or (vinfo-get vinfo #:accmap)
+ (conj-info #:accmap conj)
+ "000000")))
+ (list (vinfo-get vinfo #:conj)
+ attested))
+ fold-id)
+ prev))))
+ prev
+ aparemfato-list)))
+ ((and (string=? (conj-info #:thema conj) "synt")
+ (conj-info #:auxtense conj))
+ (let ((part (conj-info #:particle conj)))
+ (fold-right
+ (lambda (tenses prev)
+ (cons
+ (cons
+ (append
+ (map
+ (lambda (t)
+ (elstr->string (elstr-append part " " t)))
+ (list-head tenses 6))
+ (list-tail tenses 6))
+ (conj-info #:fold conj))
+ prev))
+ prev
+ (conjugate vinfo voice "ind"
+ (conj-info #:auxtense conj) #:noload))))
+ (else
+ (let ((vinfo (copy-tree vinfo)))
+ (if (vinfo-get vinfo #:stem)
+ (vinfo-set! vinfo #:attested 'stem)
+ (let ((thema (string-split
+ (conj-info #:thema conj) #\:)))
+; (format #t "THEMA ~A~%" thema)
+ (complement-verb-info vinfo verb
+ (if (null? (cdr thema))
+ voice
+ (car (cdr thema)))
+ (car thema))))
+
+ (fold
+ (lambda (suffix prev)
+ (append
+ (fold
+ (lambda (stem prev)
+ (cons
+ (cons
+ (append (apply-flect conj vinfo verb stem suffix)
+ (list (vinfo-get vinfo #:conj)
+ (vinfo-get vinfo #:attested)))
+ (conj-info #:fold conj))
+ prev))
+ '()
+ (vinfo-get vinfo #:stem))
+ prev))
+ prev
+ (get-suffix conj vinfo))))))
+ '()
+ conj-list)))))))))
+
+(define-public (conjugator:open-verb verb)
+ (create-basic-verb-info verb))
(define-public (conjugator verb voice mood tense)
- (conjugate verb voice mood tense))
+ (conjugate (conjugator:open-verb verb) voice mood tense))
(define-public (conjugation:table conj)
(cond

Return to:

Send suggestions and report system problems to the System administrator.