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 1377, Wed May 21 17:15:56 2014 UTC revision 1404, Tue Feb 17 18:04:22 2015 UTC
# Line 9  Line 9 
9    
10      readerControl <- prepareReader(readerControl, reader(x))      readerControl <- prepareReader(readerControl, reader(x))
11    
     if (is.function(readerControl$init))  
         readerControl$init()  
   
     if (is.function(readerControl$exit))  
         on.exit(readerControl$exit())  
   
12      if (!filehash::dbCreate(dbControl$dbName, dbControl$dbType))      if (!filehash::dbCreate(dbControl$dbName, dbControl$dbType))
13          stop("error in creating database")          stop("error in creating database")
14      db <- filehash::dbInit(dbControl$dbName, dbControl$dbType)      db <- filehash::dbInit(dbControl$dbName, dbControl$dbType)
15    
16        x <- open(x)
17      tdl <- vector("list", length(x))      tdl <- vector("list", length(x))
18      counter <- 1      counter <- 1
19      while (!eoi(x)) {      while (!eoi(x)) {
# Line 31  Line 26 
26          tdl[[counter]] <- meta(doc, "id")          tdl[[counter]] <- meta(doc, "id")
27          counter <- counter + 1          counter <- counter + 1
28      }      }
29        x <- close(x)
30    
31      structure(list(content = tdl,      p <- list(content = tdl,
32                     meta = CorpusMeta(),                     meta = CorpusMeta(),
33                     dmeta = data.frame(row.names = seq_along(tdl)),                     dmeta = data.frame(row.names = seq_along(tdl)),
34                     dbcontrol = dbControl),                dbcontrol = dbControl)
35                class = c("PCorpus", "Corpus"))      class(p) <- c("PCorpus", "Corpus")
36        p
37  }  }
38    
39  Corpus <-  Corpus <-
# Line 47  Line 44 
44    
45      readerControl <- prepareReader(readerControl, reader(x))      readerControl <- prepareReader(readerControl, reader(x))
46    
47      if (is.function(readerControl$init))      x <- open(x)
         readerControl$init()  
   
     if (is.function(readerControl$exit))  
         on.exit(readerControl$exit())  
   
48      tdl <- vector("list", length(x))      tdl <- vector("list", length(x))
49      # Check for parallel element access      # Check for parallel element access
50      if (is.function(getS3method("pGetElem", class(x), TRUE)))      if (is.function(getS3method("pGetElem", class(x), TRUE)))
# Line 73  Line 65 
65              counter <- counter + 1              counter <- counter + 1
66          }          }
67      }      }
68        x <- close(x)
69    
70      structure(list(content = tdl,      v <- list(content = tdl,
71                     meta = CorpusMeta(),                     meta = CorpusMeta(),
72                     dmeta = data.frame(row.names = seq_along(tdl))),                dmeta = data.frame(row.names = seq_along(tdl)))
73                class = c("VCorpus", "Corpus"))      class(v) <- c("VCorpus", "Corpus")
74        v
75  }  }
76    
77  `[.PCorpus` <-  `[.PCorpus` <-
# Line 180  Line 174 
174      if (!all(unlist(lapply(args, inherits, class(x)))))      if (!all(unlist(lapply(args, inherits, class(x)))))
175          stop("not all arguments are of the same corpus type")          stop("not all arguments are of the same corpus type")
176    
177      structure(list(content = do.call("c", lapply(args, content)),      v <- list(content = do.call("c", lapply(args, content)),
178                     meta = CorpusMeta(meta = do.call("c",                     meta = CorpusMeta(meta = do.call("c",
179                       lapply(args, function(a) meta(a, type = "corpus")))),                       lapply(args, function(a) meta(a, type = "corpus")))),
180                     dmeta = Reduce(outer_union, lapply(args, meta))),                dmeta = Reduce(outer_union, lapply(args, meta)))
181                class = c("VCorpus", "Corpus"))      class(v) <- c("VCorpus", "Corpus")
182        v
183  }  }
184    
185  content.VCorpus <-  content.VCorpus <-
# Line 222  Line 217 
217  function(x)  function(x)
218      as.character(meta(x, "id", "local"))      as.character(meta(x, "id", "local"))
219    
220    `names<-.PCorpus` <- `names<-.VCorpus` <-
221    function(x, value)
222    {
223        meta(x, "id", "local") <- as.character(value)
224        x
225    }
226    
227  print.PCorpus <- print.VCorpus <-  print.PCorpus <- print.VCorpus <-
228  function(x, ...)  function(x, ...)
229  {  {

Legend:
Removed from v.1377  
changed lines
  Added in v.1404

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