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 946, Wed May 13 18:07:35 2009 UTC revision 950, Thu May 14 15:17:18 2009 UTC
# Line 1  Line 1 
1  # Author: Ingo Feinerer  # Author: Ingo Feinerer
2    
3    FCorpus <- function(object, readerControl = list(language = "eng")) {
4        if (is.null(readerControl$language))
5            readerControl$language <- "eng"
6    
7        if (!object@Vectorized)
8            stop("Source is not vectorized")
9    
10        tdl <- lapply(mapply(c, pGetElem(object), id = seq_len(object@Length), SIMPLIFY = FALSE),
11                      function(x) readSlim(x[c("content", "uri")],
12                                           readerControl$language,
13                                           as.character(x$id)))
14    
15        new("FCorpus", .Data = tdl)
16    }
17    
18  PCorpus <- function(object,  PCorpus <- function(object,
19                      readerControl = list(reader = object@DefaultReader, language = "eng"),                      readerControl = list(reader = object@DefaultReader, language = "eng"),
20                      dbControl = list(dbName = "", dbType = "DB1"),                      dbControl = list(dbName = "", dbType = "DB1"),
# Line 91  Line 106 
106    
107  setGeneric("tmMap", function(object, FUN, ..., lazy = FALSE) standardGeneric("tmMap"))  setGeneric("tmMap", function(object, FUN, ..., lazy = FALSE) standardGeneric("tmMap"))
108  setMethod("tmMap",  setMethod("tmMap",
109              signature(object = "FCorpus", FUN = "function"),
110              function(object, FUN, ..., lazy = FALSE) {
111                  if (lazy)
112                      warning("lazy mapping is deactivated")
113    
114                  lapply(object, FUN, ..., DMetaData = data.frame())
115              })
116    setMethod("tmMap",
117            signature(object = "SCorpus", FUN = "function"),            signature(object = "SCorpus", FUN = "function"),
118            function(object, FUN, ..., lazy = FALSE) {            function(object, FUN, ..., lazy = FALSE) {
119                result <- object                result <- object
# Line 361  Line 384 
384      return(list(root = set_id(object), left.mapping = left.mapping, right.mapping = mapping))      return(list(root = set_id(object), left.mapping = left.mapping, right.mapping = mapping))
385  }  }
386    
387  # TODO: Implement concatenation for PCorpus  # TODO: Implement concatenation for other corpus types
388  setMethod("c",  setMethod("c",
389            signature(x = "Corpus"),            signature(x = "Corpus"),
390            function(x, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) {            function(x, ..., meta = list(merge_date = as.POSIXlt(Sys.time(), tz = "GMT"), merger = Sys.getenv("LOGNAME")), recursive = TRUE) {
# Line 475  Line 498 
498      db <- filehash::dbInit(DBControl(x)[["dbName"]], DBControl(x)[["dbType"]])      db <- filehash::dbInit(DBControl(x)[["dbName"]], DBControl(x)[["dbType"]])
499      show(filehash::dbMultiFetch(db, unlist(x)))      show(filehash::dbMultiFetch(db, unlist(x)))
500  }  }
501  inspect.SCorpus <- function(x) {  inspect.FCorpus <- inspect.SCorpus <- function(x) {
502      summary(x)      summary(x)
503      cat("\n")      cat("\n")
504      print(noquote(lapply(x, identity)))      print(noquote(lapply(x, identity)))

Legend:
Removed from v.946  
changed lines
  Added in v.950

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