SCM

SCM Repository

[tm] Diff of /pkg/R/corpus.R
ViewVC logotype

Diff of /pkg/R/corpus.R

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

revision 950, Thu May 14 15:17:18 2009 UTC revision 952, Mon May 18 13:43:01 2009 UTC
# Line 111  Line 111 
111                if (lazy)                if (lazy)
112                    warning("lazy mapping is deactivated")                    warning("lazy mapping is deactivated")
113    
114                lapply(object, FUN, ..., DMetaData = data.frame())                new("FCorpus", .Data = lapply(object, FUN, ..., DMetaData = data.frame()))
115            })            })
116  setMethod("tmMap",  setMethod("tmMap",
117            signature(object = "SCorpus", FUN = "function"),            signature(object = "SCorpus", FUN = "function"),
# Line 277  Line 277 
277  }  }
278    
279  setMethod("[",  setMethod("[",
280              signature(x = "FCorpus", i = "ANY", j = "ANY", drop = "ANY"),
281              function(x, i, j, ... , drop) {
282                  if (missing(i)) return(x)
283    
284                  x@.Data <- x@.Data[i, ..., drop = FALSE]
285                  x
286              })
287    setMethod("[",
288            signature(x = "PCorpus", i = "ANY", j = "ANY", drop = "ANY"),            signature(x = "PCorpus", i = "ANY", j = "ANY", drop = "ANY"),
289            function(x, i, j, ... , drop) {            function(x, i, j, ... , drop) {
290                if (missing(i)) return(x)                if (missing(i)) return(x)
# Line 287  Line 295 
295                else x@DMetaData[[1 , "subset"]] <- index[i]                else x@DMetaData[[1 , "subset"]] <- index[i]
296                x                x
297            })            })
   
298  setMethod("[",  setMethod("[",
299            signature(x = "SCorpus", i = "ANY", j = "ANY", drop = "ANY"),            signature(x = "SCorpus", i = "ANY", j = "ANY", drop = "ANY"),
300            function(x, i, j, ... , drop) {            function(x, i, j, ... , drop) {
# Line 381  Line 388 
388          return(object)          return(object)
389      }      }
390    
391      return(list(root = set_id(object), left.mapping = left.mapping, right.mapping = mapping))      list(root = set_id(object), left.mapping = left.mapping, right.mapping = mapping)
392  }  }
393    
394  # TODO: Implement concatenation for other corpus types  # TODO: Implement concatenation for other corpus types
# Line 389  Line 396 
396            signature(x = "Corpus"),            signature(x = "Corpus"),
397            function(x, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) {            function(x, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) {
398                args <- list(...)                args <- list(...)
399                if (length(args) == 0)                if (identical(length(args), 0)) return(x)
                   return(x)  
400    
401                if (!all(sapply(args, inherits, "SCorpus")))                if (!all(sapply(args, inherits, class(x))))
402                    stop("not all arguments are standard corpora")                    stop("not all arguments are of the same class")
403    
404                Reduce(c2, base::c(list(x), args))                Reduce(c2, base::c(list(x), args))
405            })            })
406    
407  setGeneric("c2", function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) standardGeneric("c2"))  setGeneric("c2", function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) standardGeneric("c2"))
408  setMethod("c2",  setMethod("c2", signature(x = "FCorpus", y = "FCorpus"),
409            signature(x = "SCorpus", y = "SCorpus"),            function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) {
410                  new("FCorpus", .Data = c(as(x, "list"), as(y, "list")))
411              })
412    setMethod("c2", signature(x = "SCorpus", y = "SCorpus"),
413            function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) {            function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) {
414                object <- x                object <- x
415                # Concatenate data slots                # Concatenate data slots
# Line 448  Line 457 
457                y.dmeta.aug <- cbind(DMetaData(y), na.matrix)                y.dmeta.aug <- cbind(DMetaData(y), na.matrix)
458                object@DMetaData <- rbind(x.dmeta.aug, y.dmeta.aug)                object@DMetaData <- rbind(x.dmeta.aug, y.dmeta.aug)
459    
460                return(object)                object
461            })            })
462    
463  setMethod("c",  setMethod("c",

Legend:
Removed from v.950  
changed lines
  Added in v.952

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