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 1102, Sat Oct 16 10:01:09 2010 UTC revision 1114, Fri Nov 26 14:05:54 2010 UTC
# Line 15  Line 15 
15                      ...) {                      ...) {
16      readerControl <- prepareReader(readerControl, x$DefaultReader, ...)      readerControl <- prepareReader(readerControl, x$DefaultReader, ...)
17    
18        if (is.function(readerControl$init))
19            readerControl$init()
20    
21        if (is.function(readerControl$exit))
22            on.exit(readerControl$exit())
23    
24      if (!filehash::dbCreate(dbControl$dbName, dbControl$dbType))      if (!filehash::dbCreate(dbControl$dbName, dbControl$dbType))
25          stop("error in creating database")          stop("error in creating database")
26      db <- filehash::dbInit(dbControl$dbName, dbControl$dbType)      db <- filehash::dbInit(dbControl$dbName, dbControl$dbType)
# Line 63  Line 69 
69                                ...) {                                ...) {
70      readerControl <- prepareReader(readerControl, x$DefaultReader, ...)      readerControl <- prepareReader(readerControl, x$DefaultReader, ...)
71    
72        if (is.function(readerControl$init))
73            readerControl$init()
74    
75        if (is.function(readerControl$exit))
76            on.exit(readerControl$exit())
77    
78      # Allocate memory in advance if length is known      # Allocate memory in advance if length is known
79      tdl <- if (x$Length > 0)      tdl <- if (x$Length > 0)
80          vector("list", as.integer(x$Length))          vector("list", as.integer(x$Length))
# Line 116  Line 128 
128      x      x
129  }  }
130    
131    .map_name_index <- function(x, i) {
132        if (is.character(i)) {
133            if (is.null(names(x)))
134                match(i, meta(x, "ID", type = "local"))
135            else
136                match(i, names(x))
137        }
138        i
139    }
140    
141  `[[.PCorpus` <-  function(x, i) {  `[[.PCorpus` <-  function(x, i) {
142      if (is.character(i))      i <- .map_name_index(x, i)
         i <- match(i, meta(x, "ID", type = "local"))  
143      db <- filehash::dbInit(DBControl(x)[["dbName"]], DBControl(x)[["dbType"]])      db <- filehash::dbInit(DBControl(x)[["dbName"]], DBControl(x)[["dbType"]])
144      filehash::dbFetch(db, NextMethod("[["))      filehash::dbFetch(db, NextMethod("[["))
145  }  }
146  `[[.VCorpus` <-  function(x, i) {  `[[.VCorpus` <-  function(x, i) {
147      if (is.character(i))      i <- .map_name_index(x, i)
         i <- match(i, meta(x, "ID", type = "local"))  
148      lazyTmMap <- meta(x, tag = "lazyTmMap", type = "corpus")      lazyTmMap <- meta(x, tag = "lazyTmMap", type = "corpus")
149      if (!is.null(lazyTmMap))      if (!is.null(lazyTmMap))
150          .Call("copyCorpus", x, materialize(x, i))          .Call("copyCorpus", x, materialize(x, i))
# Line 132  Line 152 
152  }  }
153    
154  `[[<-.PCorpus` <-  function(x, i, value) {  `[[<-.PCorpus` <-  function(x, i, value) {
155        i <- .map_name_index(x, i)
156      db <- filehash::dbInit(DBControl(x)[["dbName"]], DBControl(x)[["dbType"]])      db <- filehash::dbInit(DBControl(x)[["dbName"]], DBControl(x)[["dbType"]])
157      index <- unclass(x)[[i]]      index <- unclass(x)[[i]]
158      db[[index]] <- value      db[[index]] <- value
159      x      x
160  }  }
161  `[[<-.VCorpus` <-  function(x, i, value) {  `[[<-.VCorpus` <-  function(x, i, value) {
162        i <- .map_name_index(x, i)
163      # Mark new objects as not active for lazy mapping      # Mark new objects as not active for lazy mapping
164      lazyTmMap <- meta(x, tag = "lazyTmMap", type = "corpus")      lazyTmMap <- meta(x, tag = "lazyTmMap", type = "corpus")
165      if (!is.null(lazyTmMap)) {      if (!is.null(lazyTmMap)) {

Legend:
Removed from v.1102  
changed lines
  Added in v.1114

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