SCM

SCM Repository

[tm] Diff of /trunk/tm/R/textdoccol.R
ViewVC logotype

Diff of /trunk/tm/R/textdoccol.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 720, Tue Mar 20 10:43:11 2007 UTC revision 721, Wed Mar 21 13:54:43 2007 UTC
# Line 231  Line 231 
231            })            })
232    
233  sFilter <- function(object, s, ...) {  sFilter <- function(object, s, ...) {
     query.df <- DMetaData(object)  
234      con <- textConnection(s)      con <- textConnection(s)
235      tokens <- scan(con, "character")      tokens <- scan(con, "character")
236      close(con)      close(con)
237      local.meta <- lapply(object, LocalMetaData)      localMetaNames <- unique(names(sapply(object, LocalMetaData)))
238      local.used.meta <- lapply(local.meta, function(x) names(x) %in% tokens)      localMetaTokens <- localMetaNames[localMetaNames %in% tokens]
239      l.meta <- NULL      query.df <- DMetaData(prescindMeta(object,
240      for (i in 1:length(object)) {                                         c("Author", "DateTimeStamp", "Description", "ID",
241          l.meta <- c(l.meta, list(local.meta[[i]][local.used.meta[[i]]]))                                           "Origin", "Heading", "Language", localMetaTokens)))
242      }      # Rename to avoid name conflicts
243      # Load local meta data from text documents into data frame      names(query.df)[names(query.df) == "Author"] <- "author"
244      for (i in 1:length(l.meta)) {      names(query.df)[names(query.df) == "DateTimeStamp"] <- "datetimestamp"
245          l.meta[[i]] <- c(l.meta[[i]], list(author = Author(object[[i]])))      names(query.df)[names(query.df) == "Description"] <- "description"
246          l.meta[[i]] <- c(l.meta[[i]], list(datetimestamp = DateTimeStamp(object[[i]])))      names(query.df)[names(query.df) == "ID"] <- "identifier"
247          l.meta[[i]] <- c(l.meta[[i]], list(description = Description(object[[i]])))      names(query.df)[names(query.df) == "Origin"] <- "origin"
248          l.meta[[i]] <- c(l.meta[[i]], list(identifier = ID(object[[i]])))      names(query.df)[names(query.df) == "Heading"] <- "heading"
249          l.meta[[i]] <- c(l.meta[[i]], list(origin = Origin(object[[i]])))      names(query.df)[names(query.df) == "Language"] <- "language"
         l.meta[[i]] <- c(l.meta[[i]], list(heading = Heading(object[[i]])))  
     }  
     for (i in 1:length(l.meta)) {  
         for (j in 1:length(l.meta[[i]])) {  
             m <- l.meta[[i]][[j]]  
             m.name <- names(l.meta[[i]][j])  
             if (!(m.name %in% names(query.df))) {  
                 before <- rep(NA, i - 1)  
                 after <- rep(NA, length(l.meta) - i)  
                 if (length(m) > 1) {  
                     nl <- vector("list", length(l.meta))  
                     nl[1:(i-1)] <- before  
                     nl[i] <- list(m)  
                     nl[(i+1):length(l.meta)] <- after  
                     insert <- data.frame(I(nl), stringsAsFactors = FALSE)  
                 }  
                 else  
                     insert <- c(before, m, after)  
                 query.df <- cbind(query.df, insert, stringsAsFactors = FALSE)  
                 names(query.df)[length(query.df)] <- m.name  
             }  
             else {  
                 if (is.null(m))  
                     m <- NA  
                 if (length(m) > 1) {  
                     rl <- query.df[ , m.name]  
                     rl[i] <- list(m)  
                     query.df[ , m.name] <- data.frame(I(rl), stringsAsFactors = FALSE)  
                 }  
                 else  
                     query.df[i, m.name] <- m  
             }  
         }  
     }  
250      attach(query.df)      attach(query.df)
251      try(result <- rownames(query.df) %in% row.names(query.df[eval(parse(text = s)), ]))      try(result <- rownames(query.df) %in% row.names(query.df[eval(parse(text = s)), ]))
252      detach(query.df)      detach(query.df)
# Line 337  Line 302 
302                return(object)                return(object)
303            })            })
304    
305    # WARNING: If dbUse the augmented dataframe is stored (watch out since sFilter calls this method)
306  setGeneric("prescindMeta", function(object, meta) standardGeneric("prescindMeta"))  setGeneric("prescindMeta", function(object, meta) standardGeneric("prescindMeta"))
307  setMethod("prescindMeta",  setMethod("prescindMeta",
308            signature(object = "TextDocCol", meta = "character"),            signature(object = "TextDocCol", meta = "character"),
# Line 346  Line 312 
312                        local.m <- lapply(object, m)                        local.m <- lapply(object, m)
313                        local.m <- lapply(local.m, function(x) if (is.null(x)) return(NA) else return(x))                        local.m <- lapply(local.m, function(x) if (is.null(x)) return(NA) else return(x))
314                        local.m <- unlist(local.m)                        local.m <- unlist(local.m)
315                        DMetaData(object) <- cbind(DMetaData(object), data.frame(m = local.m), stringsAsFactors = FALSE)                        DMetaData(object) <- cbind(DMetaData(object), data.frame(m = local.m, stringsAsFactors = FALSE))
316                        names(DMetaData(object))[length(DMetaData(object))] <- m                        names(DMetaData(object))[which(names(DMetaData(object)) == "m")] <- m
317                    }                    }
318                    else {                    else {
319                        local.meta <- lapply(object, LocalMetaData)                        local.meta <- lapply(object, LocalMetaData)
# Line 357  Line 323 
323                            local.m <- unlist(local.m)                            local.m <- unlist(local.m)
324                        else                        else
325                            local.m <- I(local.m)                            local.m <- I(local.m)
326                        DMetaData(object) <- cbind(DMetaData(object), data.frame(m = local.m), stringsAsFactors = FALSE)                        DMetaData(object) <- cbind(DMetaData(object), data.frame(m = local.m, stringsAsFactors = FALSE))
327                        names(DMetaData(object))[length(DMetaData(object))] <- m                        names(DMetaData(object))[which(names(DMetaData(object)) == "m")] <- m
328                    }                    }
329                }                }
330                return(object)                return(object)

Legend:
Removed from v.720  
changed lines
  Added in v.721

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