Total members 11678 |It is currently Sat Nov 25, 2017 3:35 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





This code shows an example on how to use Latent semantic analysis approach (LSA) in R scripting.
Code:
require(lsr)
require(
foreign)

require(
MASS)
require(
bootES)
library(lsa)

require(
corrgram)



setwd("D:/FirstPaper/FireFox/NewRQ/")


td = tempfile()
dir.create(td)
write( c("man", "cat", "donkey"), file=paste(td, "D1", sep="/"))
write( c("hamster", "donkey", "sushi"), file=paste(td, "D2", sep="/"))
write( c("man", "monster", "monster"), file=paste(td, "D3", sep="/"))
write( c("man", "donkey", "man"), file=paste(td, "D4", sep="/"))


# create matrices
myMatrix = textmatrix(td, minWordLength=1)
myMatrix
myLSAspace 
= lsa(myMatrix, dims=dimcalc_share())
myLSAspace
myNewMatrix 
= as.textmatrix(myLSAspace)

as.
textmatrix(myLSAspace)


# calc associations for donkey
associate(myNewMatrix, "donkey")
# clean up
unlink(td, recursive=TRUE)


data(corpus_training)
 
data
(corpus_essays)
data(corpus_scores)

vec1 = c( 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
vec2 = c( 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 )
vec3 = c( 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0 )
matrix = cbind(vec1,vec2, vec3)

cosine(matrix)


# create some files
td = tempfile()
dir.create(td)
write( c("man", "cat", "donkey"), file=paste(td, "D1", sep="/"))
write( c("hamster", "donkey", "sushi"), file=paste(td, "D2", sep="/"))
write( c("man", "monster", "monster"), file=paste(td, "D3", sep="/"))
write( c("man", "donkey", "man"), file=paste(td, "D4", sep="/"))
# create matrices
myMatrix = textmatrix(td, minWordLength=1)
sample(myMatrix, 3)
# clean up
unlink(td, recursive=TRUE)


data(stopwords_en);



# create some files
td = tempfile()
dir.create(td)
write( c("while", "dance", "donkey","fifa"), file=paste(td, "D1", sep="/"))
write( c("hamster", "dance", "sushi"), file=paste(td, "D2", sep="/"))
write( c("man", "monster", "monster"), file=paste(td, "D3", sep="/"))
write( c("man", "dance", "man"), file=paste(td, "D4", sep="/"))
# create matrices
myMatrix = textmatrix(td, minWordLength=1,stopwords=stopwords_en,stemming=TRUE, language="english", minDocFreq=1)
myMatrix
# clean up
unlink(td, recursive=TRUE)



To understand the meaning of each function used in the code above, please check the user manual of "lsr" package.



_________________
Sami
PHD student - SAIL - School Of Computing
Queens' University
Canada


Author:
Site Admin
User avatar Posts: 33
Have thanks: 1 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Latent semantic analysis for Text in R using LSA
 Human Voice Analysis in java     -  
 Learn Technical analysis and stock market tricks for free     -  
 Able to Copy Text from Uneditable Text Boxes(JTextfields)     -  
 Java- Copy text area into disabled text area     -  
 text like a curve     -  
 Aligning the text within the div tag     -  
 i tag for italic text     -  
 Get Text Field value by php     -  
 Flaming Text     -  
 Transparent Text     -  



Topic Tags

R Classifiers







Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team