Exercise 4.48: add parsing of adjectives
This commit is contained in:
parent
dfd65eed08
commit
b99442949d
|
@ -4,6 +4,8 @@
|
|||
|
||||
(define articles '(article the a))
|
||||
|
||||
(define adjectives '(adjective happy lazy))
|
||||
|
||||
;; output of parse
|
||||
'(sentence (noun-phrase (article the) (noun cat))
|
||||
(verb eats))
|
||||
|
@ -40,6 +42,7 @@
|
|||
|
||||
(define prepositions '(prep for to in by with))
|
||||
|
||||
|
||||
(define (parse-prepositional-phrase)
|
||||
(list 'prep-phrase
|
||||
(parse-word prepositions)
|
||||
|
@ -58,10 +61,11 @@
|
|||
(parse-prepositional-phrase)))))
|
||||
(maybe-extend (parse-word verbs)))
|
||||
|
||||
;; Extend this to allow an adjective between the article and noun.
|
||||
(define (parse-simple-noun-phrase)
|
||||
(list 'simple-noun-phrase
|
||||
(parse-word articles)
|
||||
(parse-word nouns)))
|
||||
(parse-adjective-phrase)))
|
||||
|
||||
(define (parse-noun-phrase)
|
||||
(define (maybe-extend noun-phrase)
|
||||
|
@ -71,6 +75,14 @@
|
|||
(parse-prepositional-phrase)))))
|
||||
(maybe-extend (parse-simple-noun-phrase)))
|
||||
|
||||
;; An adjective phrase is any number of adjectives followed by a
|
||||
;; simple noun.
|
||||
(define (parse-adjective-phrase)
|
||||
(amb (list (parse-word nouns))
|
||||
(cons
|
||||
(parse-word adjectives)
|
||||
(parse-adjective-phrase))))
|
||||
|
||||
|
||||
;; Exercise 4.45: Output of (parse '(the professor lectures to the student in the class with the cat))
|
||||
|
||||
|
|
Loading…
Reference in New Issue