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 828, Sun Mar 9 07:47:15 2008 UTC revision 829, Mon Mar 10 22:55:39 2008 UTC
# Line 174  Line 174 
174                }                }
175                else {                else {
176                    if (lazy)                    if (lazy)
177                        meta(result, tag = "lazyTmMap", type = "corpus") <- list(fun = FUN, args = ...)                        meta(result, tag = "lazyTmMap", type = "corpus") <-
178                              list(index = rep(TRUE, length(result)),
179                                   fun = FUN,
180                                   args = ...)
181                    else                    else
182                        result@.Data <- lapply(object, FUN, ..., DMetaData = DMetaData(object))                        result@.Data <- lapply(object, FUN, ..., DMetaData = DMetaData(object))
183                }                }
# Line 182  Line 185 
185            })            })
186    
187  # Materialize lazy mappings  # Materialize lazy mappings
188  materialize <- function(corpus) {  # ToDo: Clean up lazyTmMap markers (for the case that everything is materialized)
189    materialize <- function(corpus, range = seq_along(corpus)) {
190      lazyTmMap <- meta(corpus, tag = "lazyTmMap", type = "corpus")      lazyTmMap <- meta(corpus, tag = "lazyTmMap", type = "corpus")
191      if (!is.null(lazyTmMap))      if (!is.null(lazyTmMap)) {
192          corpus@.Data <- lapply(corpus, lazyTmMap$fun, DMetaData = DMetaData(corpus))          for (i in range)
193                if (lazyTmMap$index[i]) {
194                    corpus@.Data[[i]] <- lazyTmMap$fun(corpus@.Data[[i]], lazyTmMap$args, DMetaData = DMetaData(corpus))
195                    lazyTmMap$index[i] <- FALSE
196                }
197        }
198        meta(corpus, tag = "lazyTmMap", type = "corpus") <- lazyTmMap
199      return(corpus)      return(corpus)
200  }  }
201    
# Line 401  Line 411 
411            })            })
412    
413  # ToDo: Implement on-demand materialization of lazy mappings  # ToDo: Implement on-demand materialization of lazy mappings
414    ############################################
415    # Lazy mapping restrictions (at the moment):
416    #   *) No database backend support
417    ############################################
418  setMethod("[[",  setMethod("[[",
419            signature(x = "Corpus", i = "ANY", j = "ANY"),            signature(x = "Corpus", i = "ANY", j = "ANY"),
420            function(x, i, j, ...) {            function(x, i, j, ...) {
# Line 409  Line 423 
423                    result <- dbFetch(db, x@.Data[[i]])                    result <- dbFetch(db, x@.Data[[i]])
424                    return(loadDoc(result))                    return(loadDoc(result))
425                }                }
426                else                else {
427                      # ToDo: Ensure that loadDoc is called and cached
428                      .Call("copyCorpus", x, materialize(x, i))
429                    return(loadDoc(x@.Data[[i]]))                    return(loadDoc(x@.Data[[i]]))
430                  }
431            })            })
432    
433    # ToDo: Mark set objects as not active for lazy mapping
434  setMethod("[[<-",  setMethod("[[<-",
435            signature(x = "Corpus", i = "ANY", j = "ANY", value = "ANY"),            signature(x = "Corpus", i = "ANY", j = "ANY", value = "ANY"),
436            function(x, i, j, ..., value) {            function(x, i, j, ..., value) {

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

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