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 826, Sat Feb 23 14:38:15 2008 UTC revision 828, Sun Mar 9 07:47:15 2008 UTC
# Line 153  Line 153 
153                return(object)                return(object)
154            })            })
155    
156  setGeneric("tmMap", function(object, FUN, ...) standardGeneric("tmMap"))  setGeneric("tmMap", function(object, FUN, lazy = FALSE, ...) standardGeneric("tmMap"))
157    ############################################
158    # Lazy mapping restrictions (at the moment):
159    #   *) No database backend support
160    #   *) No function composition
161    ############################################
162  setMethod("tmMap",  setMethod("tmMap",
163            signature(object = "Corpus", FUN = "function"),            signature(object = "Corpus", FUN = "function"),
164            function(object, FUN, ...) {            function(object, FUN, lazy = FALSE, ...) {
165                result <- object                result <- object
166                # Note that text corpora are automatically loaded into memory via \code{[[}                # Note that text corpora are automatically loaded into memory via \code{[[}
167                if (DBControl(object)[["useDb"]]) {                if (DBControl(object)[["useDb"]]) {
# Line 167  Line 172 
172                        i <- i + 1                        i <- i + 1
173                    }                    }
174                }                }
175                  else {
176                      if (lazy)
177                          meta(result, tag = "lazyTmMap", type = "corpus") <- list(fun = FUN, args = ...)
178                else                else
179                    result@.Data <- lapply(object, FUN, ..., DMetaData = DMetaData(object))                    result@.Data <- lapply(object, FUN, ..., DMetaData = DMetaData(object))
180                  }
181                return(result)                return(result)
182            })            })
183    
184    # Materialize lazy mappings
185    materialize <- function(corpus) {
186        lazyTmMap <- meta(corpus, tag = "lazyTmMap", type = "corpus")
187        if (!is.null(lazyTmMap))
188            corpus@.Data <- lapply(corpus, lazyTmMap$fun, DMetaData = DMetaData(corpus))
189        return(corpus)
190    }
191    
192  setGeneric("asPlain", function(object, FUN, ...) standardGeneric("asPlain"))  setGeneric("asPlain", function(object, FUN, ...) standardGeneric("asPlain"))
193  setMethod("asPlain",  setMethod("asPlain",
194            signature(object = "PlainTextDocument"),            signature(object = "PlainTextDocument"),
# Line 383  Line 400 
400                return(object)                return(object)
401            })            })
402    
403    # ToDo: Implement on-demand materialization of lazy mappings
404  setMethod("[[",  setMethod("[[",
405            signature(x = "Corpus", i = "ANY", j = "ANY"),            signature(x = "Corpus", i = "ANY", j = "ANY"),
406            function(x, i, j, ...) {            function(x, i, j, ...) {

Legend:
Removed from v.826  
changed lines
  Added in v.828

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