# NOT RUN {
# create some files
td = tempfile()
dir.create(td)
write( c("dog", "cat", "mouse"), file=paste(td, "D1", sep="/"))
write( c("hamster", "mouse", "sushi"), file=paste(td, "D2", sep="/"))
write( c("dog", "monster", "monster"), file=paste(td, "D3", sep="/"))
write( c("dog", "mouse", "dog"), file=paste(td, "D4", sep="/"))
# read files into a document-term matrix
myMatrix = textmatrix(td, minWordLength=1)
# create the latent semantic space
myLSAspace = lsa(myMatrix, dims=dimcalc_raw())
# display it as a textmatrix again
round(as.textmatrix(myLSAspace),2) # should give the original
# create the latent semantic space
myLSAspace = lsa(myMatrix, dims=dimcalc_share())
# display it as a textmatrix again
myNewMatrix = as.textmatrix(myLSAspace)
myNewMatrix # should look be different!
# compare two terms with the cosine measure
cosine(myNewMatrix["dog",], myNewMatrix["cat",])
# compare two documents with pearson
cor(myNewMatrix[,1], myNewMatrix[,2], method="pearson")
# clean up
unlink(td, recursive=TRUE)
# }
Run the code above in your browser using DataLab