#lang racket/base

; Model and generation of genders
(provide
  ; Gender collection functions
  jsexpr->genders
  genders-ref
  ; Gender structure accessors
  gender-name gender-title gender-title-abbreviation
  gender-subject gender-object gender-genitive gender-reflexive
  gender-plural?
  )

; Gender structure
(struct gender
  (name
   title
   title-abbreviation
   subject
   object
   genitive
   reflexive
   plural?))

; Gender collection constructor
(define (jsexpr->genders js)
  (define ret (make-hash))
  (map
    (lambda (x)
      (define name (hash-ref x 'name))
      (hash-set! ret name
        (gender
          name
          (hash-ref x 'title)
          (hash-ref x 'title-abbreviation)
          (hash-ref x 'subject)
          (hash-ref x 'object)
          (hash-ref x 'genitive)
          (hash-ref x 'reflexive)
          (hash-ref x 'plural?))))
    js)
  ret)

; Get a gender by its name
(define (genders-ref gnd name)
  (hash-ref gnd name))
