Voorbeeld van een boom in SCHEME:
(define tree '((S
(NP
(DET the)
(N man) )
(VP
(V sees)
(NP
(NP
(DET the)
(N woman) )
(PP
(P with)
(NP
(DET the)
(N camera) )))))))
(define depth-first_links
(lambda (boom)
(if (not (null? boom))
(begin
(if (symbol? (car boom))
(begin
(display (car boom))
(display " ")
)
(depth-first_links (car boom))
)
(depth-first_links (cdr boom))
) ) ) )
> (depth-first_links tree)
S NP DET the N man VP V sees NP NP DET the N woman PP P with NP DET the N camera
(define depth-first_rechts
(lambda (boom)
(if (not (null? boom))
(begin
(if (not (symbol? (car boom)))
(depth-first_rechts (car boom))
)
(depth-first_rechts (cdr boom))
(if (symbol? (car boom))
(begin
(display (car boom))
(display " ")
) ) ) ) ) )
> (depth-first_rechts tree)
the DET man N NP sees V the DET woman N NP with P the DET camera N NP PP NP VP S
Verdere tekst komt nog!
Opdracht
1
Schrijf een functie die alleen de woorden uit een boom print:
>(woorden tree)
the man sees the woman with the camera
2
Schrijf een functie die alleen de woordsoorten (parts-of-speech) uit een boom print:
>(pos tree)
DET N V DET N P DET N
3
Schrijf een functie die een boom breadth-first afdrukt.
Voorbeeld:
> (breadth-first tree)
S
NP VP
DET the N man V sees NP
NP PP
DET the N woman P with NP
DET the N camera
of mooier:
> (breadth-first2 tree)
S
NP VP
DET N V NP
the man sees NP PP
DET N P NP
the woman with DET N
the camera