Total members 11621 |It is currently Wed Mar 29, 2017 7:55 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka

All times are UTC [ DST ]



  Latent semantic analysis for Text in R using LSA
Tue Dec 16, 2014 6:21 am 

This code shows example on how to using 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)





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


Author:
Site Admin
User avatar Posts: 34
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     -  
 Flaming Text     -  
 Transparent Text     -  
 text like a curve     -  
 Aligning the text within the div tag     -  
 i tag for italic text     -  
 Get Text Field value by php     -  

All times are UTC [ DST ]



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