Functional Programming, Assignment 2000

Last updated 12.10.2000
Index

Use Scheme to implement a simple concordance package., i.e., a package to be used for textual analysis. The user functions to be defined are wordcount, type-token-ratio, frequency-table, index, and concord. These are exemplified below but more detailed definitions wíll be given, see the class folder. Plan what help functions are needed and implement these first.

Given the text
butler: '(I do not mind lying but I hate inaccuracy)
the output should be (formatting is not important):

>>>(wordcount butler)
9
>>>(type-token-ratio butler)
0.888888888

>>>(frequency-table butler)     >>>(index butler)
I		2		I		1,7
but		1		but		6
do		1		do		2
hate		1		hate		8
inaccuracy	1		inaccuracy	9
lying		1		lying		5
mind		1		mind		4
not		1		not		3

>>>(concordance butler 1); 1 is the size of the context
		I		do		1
but		I		hate		7
lying		but		I		6
I		do		not		2
I		hate		inaccuracy	8
hate		inaccuracy			9
mind		lying		but		5
not		mind		lying		4
do		not		mind		3
The following functions may be of interest when constructing a concordance package (see also Chapter 6).
; Converting between symbols and strings
>>>(symbol->string 'aimo)
"aimo"
>>>(string->symbol "aimo")
aimo

; Sorting list of strings
>>>(sort '("alpha" "delta" "beta") string>?)
("delta" "beta" "alpha")      
>>>(sort '("alpha" "delta" "beta") string>>(string->list "Aimo")
(#\A #\i #\m #\o)
>>>(list->string '(#\A #\i #\m #\o))
"Aimo"