SCM

SCM Repository

[tm] Diff of /trunk/tm/R/distmeasure.R
ViewVC logotype

Diff of /trunk/tm/R/distmeasure.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 52, Sat Aug 12 12:43:39 2006 UTC revision 53, Thu Aug 24 13:06:50 2006 UTC
# Line 1  Line 1 
1  # Author: Ingo Feinerer  # Author: Ingo Feinerer
2    
3  dist.tdm <- function(x, diag = FALSE, upper = FALSE, method = "cosine") {  setGeneric("dissimilarity", function(x, y, method) standardGeneric("dissimilarity"))
4    setMethod("dissimilarity",
5              signature(x = "TermDocMatrix", y = "ANY", method = "character"),
6              function(x, y = NULL, method = "cosine") {
7      type <- match.arg(method, c("cosine","pearson","extjacc"))      type <- match.arg(method, c("cosine","pearson","extjacc"))
8    
9      m <- matrix(0, nrow = nrow(x), ncol = nrow(x))      m <- matrix(0, nrow = nrow(x), ncol = nrow(x))
# Line 37  Line 40 
40      }      }
41      attr(d, "Size") <- nrow(x)      attr(d, "Size") <- nrow(x)
42      attr(d, "Labels") <- dimnames(x)[[1]]      attr(d, "Labels") <- dimnames(x)[[1]]
43      attr(d, "Diag") <- diag                attr(d, "Diag") <- FALSE
44      attr(d, "Upper") <- upper                attr(d, "Upper") <- FALSE
45      switch(type,      switch(type,
46             "cosine" = {             "cosine" = {
47                 attr(d, "method") <- "cosine"                 attr(d, "method") <- "cosine"
# Line 51  Line 54 
54             }             }
55             )             )
56      class(d) <- "dist"      class(d) <- "dist"
57                  return(1 - d)
58      d            })
59  }  setMethod("dissimilarity",
60              c("TextDocument", "TextDocument", "character"),
61              function(x, y, method) {
62                  tdm <- TermDocMatrix(as(list(x,y), "TextDocCol"))
63                  dissim <- dissimilarity(tdm, method = method)
64                  class(dissim) <- "dist"
65                  return(dissim)
66              })
67    
68  cosinus <- function(x, y) {  cosinus <- function(x, y) {
69      if (!(is.vector(x) && is.vector(y)))      if (!(is.vector(x) && is.vector(y)))

Legend:
Removed from v.52  
changed lines
  Added in v.53

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge