;;; Bottom-up CKY parser ;;; Edge is represented by a rail [lvertex rvertex nonterminal trans] ;;; rule is represented by a rail [lhs rhs-except-las-reversed last transduction-function] (define add-edge (lambda [edge chart] (append chart [edge] (new-edges edge)) (define new-edges (lambda [edge] (map (lambda [rule] (if (= (third rule) (third edge)) (let [[sub-edges (get-abutting-edges (if (null list-of-nonterms) [edge] (let [[final-edges (get-final-edges (define extend (lambda [old-edge new-edge] (if (and (= (second old-edge) (first new-edge)) ; edges abut for all rules with rhs endingi nths vetex get info re rhs ending here to get info re rhs ending at end vertex of edge let rhs be right hand side get info re rhs minus last ending at first vertex add (define get-abutting-edges (lambda [nonterm-list end-vertex] (if (null nonterm-list) edge-list (cross-product-cons (get-edges (first nonterm-list) chart) (get-abutting-edges (rest-nonterm-list) chart))) (define cross-product-cons [firsts rests] (mappend (lambda [f] (map (lambda [r] (cons f r)) rests) firsts)) (define get-edges (lambda [nonterm chart] (mappend (lambda [edge] (if (= (third edge) nonterm) [edge] [])))))