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 960, Fri Jun 26 17:43:45 2009 UTC revision 962, Sun Jun 28 15:52:33 2009 UTC
# Line 10  Line 10 
10      readerControl      readerControl
11  }  }
12    
13  FCorpus <- function(object, readerControl = list(language = "eng")) {  ## Fast Corpus
14      readerControl <- prepareReader(readerControl, object@DefaultReader, ...)  ##   - provides a prototype implementation of a more time and memory efficient representation of a corpus
15    ##   - allows performance tests and comparisons to other corpus types
16      if (!object@Vectorized)  #FCorpus <- function(object, readerControl = list(language = "eng")) {
17          stop("Source is not vectorized")  #    readerControl <- prepareReader(readerControl)
18    #
19      tdl <- lapply(mapply(c, pGetElem(object), id = seq_len(object@Length), SIMPLIFY = FALSE),  #    if (!object@Vectorized)
20                    function(x) readSlim(x[c("content", "uri")],  #        stop("Source is not vectorized")
21                                         readerControl$language,  #
22                                         as.character(x$id)))  #    tdl <- lapply(mapply(c, pGetElem(object), id = seq_len(object@Length), SIMPLIFY = FALSE),
23    #                  function(x) readSlim(x[c("content", "uri")],
24      new("FCorpus", .Data = tdl)  #                                       readerControl$language,
25  }  #                                       as.character(x$id)))
26    #
27    #    new("FCorpus", .Data = tdl)
28    #}
29    
30  PCorpus <- function(object,  PCorpus <- function(object,
31                      readerControl = list(reader = object@DefaultReader, language = "eng"),                      readerControl = list(reader = object@DefaultReader, language = "eng"),
# Line 104  Line 107 
107  }  }
108    
109  setGeneric("tmMap", function(object, FUN, ..., lazy = FALSE) standardGeneric("tmMap"))  setGeneric("tmMap", function(object, FUN, ..., lazy = FALSE) standardGeneric("tmMap"))
110  setMethod("tmMap",  #setMethod("tmMap",
111            signature(object = "FCorpus", FUN = "function"),  #          signature(object = "FCorpus", FUN = "function"),
112            function(object, FUN, ..., lazy = FALSE) {  #          function(object, FUN, ..., lazy = FALSE) {
113                if (lazy)  #              if (lazy)
114                    warning("lazy mapping is deactivated")  #                  warning("lazy mapping is deactivated")
115    #
116                new("FCorpus", .Data = lapply(object, FUN, ..., DMetaData = data.frame()))  #              new("FCorpus", .Data = lapply(object, FUN, ..., DMetaData = data.frame()))
117            })  #          })
118  setMethod("tmMap",  setMethod("tmMap",
119            signature(object = "SCorpus", FUN = "function"),            signature(object = "SCorpus", FUN = "function"),
120            function(object, FUN, ..., lazy = FALSE) {            function(object, FUN, ..., lazy = FALSE) {
# Line 274  Line 277 
277      df      df
278  }  }
279    
280  setMethod("[",  #setMethod("[",
281            signature(x = "FCorpus", i = "ANY", j = "ANY", drop = "ANY"),  #          signature(x = "FCorpus", i = "ANY", j = "ANY", drop = "ANY"),
282            function(x, i, j, ... , drop) {  #          function(x, i, j, ... , drop) {
283                if (missing(i)) return(x)  #              if (missing(i)) return(x)
284    #
285                x@.Data <- x@.Data[i, ..., drop = FALSE]  #              x@.Data <- x@.Data[i, ..., drop = FALSE]
286                x  #              x
287            })  #          })
288  setMethod("[",  setMethod("[",
289            signature(x = "PCorpus", i = "ANY", j = "ANY", drop = "ANY"),            signature(x = "PCorpus", i = "ANY", j = "ANY", drop = "ANY"),
290            function(x, i, j, ... , drop) {            function(x, i, j, ... , drop) {
# Line 404  Line 407 
407            })            })
408    
409  setGeneric("c2", function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME"))) standardGeneric("c2"))  setGeneric("c2", function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME"))) standardGeneric("c2"))
410  setMethod("c2", signature(x = "FCorpus", y = "FCorpus"),  #setMethod("c2", signature(x = "FCorpus", y = "FCorpus"),
411            function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME"))) {  #          function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME"))) {
412                new("FCorpus", .Data = c(as(x, "list"), as(y, "list")))  #              new("FCorpus", .Data = c(as(x, "list"), as(y, "list")))
413            })  #          })
414  setMethod("c2", signature(x = "SCorpus", y = "SCorpus"),  setMethod("c2", signature(x = "SCorpus", y = "SCorpus"),
415            function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME"))) {            function(x, y, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME"))) {
416                object <- x                object <- x
# Line 506  Line 509 
509      db <- filehash::dbInit(DBControl(x)[["dbName"]], DBControl(x)[["dbType"]])      db <- filehash::dbInit(DBControl(x)[["dbName"]], DBControl(x)[["dbType"]])
510      show(filehash::dbMultiFetch(db, unlist(x)))      show(filehash::dbMultiFetch(db, unlist(x)))
511  }  }
512  inspect.FCorpus <- inspect.SCorpus <- function(x) {  #inspect.FCorpus <-
513    inspect.SCorpus <- function(x) {
514      summary(x)      summary(x)
515      cat("\n")      cat("\n")
516      print(noquote(lapply(x, identity)))      print(noquote(lapply(x, identity)))

Legend:
Removed from v.960  
changed lines
  Added in v.962

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