NLP/0000755000175100001440000000000013362126615010726 5ustar hornikusersNLP/po/0000755000175100001440000000000013143661406011343 5ustar hornikusersNLP/po/R-NLP.pot0000644000175100001440000000330313143661406012716 0ustar hornikusersmsgid "" msgstr "" "Project-Id-Version: NLP 0.1-10.1\n" "POT-Creation-Date: 2017-08-12 22:20\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" msgid "arguments must have the same length" msgstr "" msgid "invalid element name" msgstr "" msgid "replacement must have the same length as object" msgstr "" msgid "'subset' must be logical" msgstr "" msgid "Annotators must have formals 's' and 'a'." msgstr "" msgid "Invalid result from underlying paragraph tokenizer." msgstr "" msgid "Invalid result from underlying sentence tokenizer." msgstr "" msgid "no sentence token annotations found" msgstr "" msgid "Invalid result from underlying word tokenizer." msgstr "" msgid "no word token annotations found" msgstr "" msgid "Invalid result from underlying POS tagger." msgstr "" msgid "Invalid result from underlying name finder." msgstr "" msgid "Invalid result from underlying chunker." msgstr "" msgid "all pipeline elements must be annotator objects" msgstr "" msgid "argument 'annotations' must give a positive number of Annotation objects" msgstr "" msgid "content modification is not possible for AnnotatedPlainTextDocument objects" msgstr "" msgid "argument 'x' must be an AnnotatedPlainTextDocument object" msgstr "" msgid "Cannot determine position of '%s'" msgstr "" msgid "Invalid entries:" msgstr "" msgid "Invalid language tag(s):" msgstr "" msgid "Invalid operands." msgstr "" msgid "'%s' not defined for \"Span\" objects" msgstr "" msgid "Need a non-empty string." msgstr "" msgid "end of string" msgstr "" NLP/inst/0000755000175100001440000000000013143661406011702 5ustar hornikusersNLP/inst/po/0000755000175100001440000000000013143661406012320 5ustar hornikusersNLP/inst/po/en@quot/0000755000175100001440000000000013143661406013733 5ustar hornikusersNLP/inst/po/en@quot/LC_MESSAGES/0000755000175100001440000000000013143661406015520 5ustar hornikusersNLP/inst/po/en@quot/LC_MESSAGES/R-NLP.mo0000644000175100001440000000535713143661406016717 0ustar hornikusers%@#Ae)~!*'1+Y32./4Hd9#K  We#z/7'&N1k%*'*+R3~2. /- L] = # K X f #{  /     '%s' not defined for "Span" objects'subset' must be logicalAnnotators must have formals 's' and 'a'.Cannot determine position of '%s'Invalid entries:Invalid language tag(s):Invalid operands.Invalid result from underlying POS tagger.Invalid result from underlying chunker.Invalid result from underlying name finder.Invalid result from underlying paragraph tokenizer.Invalid result from underlying sentence tokenizer.Invalid result from underlying word tokenizer.Need a non-empty string.all pipeline elements must be annotator objectsargument 'annotations' must give a positive number of Annotation objectsargument 'x' must be an AnnotatedPlainTextDocument objectarguments must have the same lengthcontent modification is not possible for AnnotatedPlainTextDocument objectsend of stringinvalid element nameno sentence token annotations foundno word token annotations foundreplacement must have the same length as objectProject-Id-Version: NLP 0.1-10.1 POT-Creation-Date: 2017-08-12 22:20 PO-Revision-Date: 2017-08-12 22:20 Last-Translator: Automatically generated Language-Team: none MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Language: en Plural-Forms: nplurals=2; plural=(n != 1); ‘%s’ not defined for "Span" objects‘subset’ must be logicalAnnotators must have formals ‘s’ and ‘a’.Cannot determine position of ‘%s’Invalid entries:Invalid language tag(s):Invalid operands.Invalid result from underlying POS tagger.Invalid result from underlying chunker.Invalid result from underlying name finder.Invalid result from underlying paragraph tokenizer.Invalid result from underlying sentence tokenizer.Invalid result from underlying word tokenizer.Need a non-empty string.all pipeline elements must be annotator objectsargument ‘annotations’ must give a positive number of Annotation objectsargument ‘x’ must be an AnnotatedPlainTextDocument objectarguments must have the same lengthcontent modification is not possible for AnnotatedPlainTextDocument objectsend of stringinvalid element nameno sentence token annotations foundno word token annotations foundreplacement must have the same length as objectNLP/inst/texts/0000755000175100001440000000000012252103770013044 5ustar hornikusersNLP/inst/texts/stanford.rds0000644000175100001440000000204113336510534015377 0ustar hornikusersYo0OʀB AUb)b  mZe J(v/@9vM++S/ܞaiXuxZP>kUc/C+'!'0ĵ=j?C=#d#!AŽ!aT͌PUУC(}W@΂{Ioc \7@A3 j95v-~OfY B1QX݂ˋ#CE6&HK=m Nfll*$ƗAd߻ [#J>a+Ϫq{{{oo@9֜TS5A:~x'.T]?P@"6S)%plG3ZS uQ Xz F<^:bI Xdp16U%L9焄E)Jek%N IYܤi%.~eL5}iG  Pɕ}pI y44VoAhNf>˨LVAe6݂& 5KLh~S[Y<ѓ xogwT-5|;Љ̭1u}ż%Kɤ e( Q=&fLI L2;">o*(G7cgCI% J4(iP࿧oMet;/?GfِqBIn֖(\'2R ZUuD:8(hV 2u䳡؉!nr歗g[pξ@CRb;2V>Ye'=‰=yt@>6(wa^jN~?!NLP/NAMESPACE0000644000175100001440000002117513362123057012150 0ustar hornikusersimportFrom("utils", "head", "tail") export("content", "content<-", "meta", "meta<-") export("String", "as.String", "is.String") S3method("as.String", "String") S3method("as.String", "default") S3method("[", "String") S3method("*", "String") S3method("+", "String") S3method("print", "String") export("Span", "as.Span", "is.Span") S3method("as.Span", "Span") S3method("as.Span", "Annotation") S3method("[", "Span") ## S3method("[<-", "Span") S3method("[[", "Span") ## S3method("[[<-", "Span") S3method("$<-", "Span") S3method("Ops", "Span") S3method("as.data.frame", "Span") S3method("as.list", "Span") S3method("c", "Span") S3method("duplicated", "Span") S3method("format", "Span") S3method("length", "Span") S3method("names", "Span") S3method("print", "Span") S3method("unique", "Span") export("Annotation", "as.Annotation", "is.Annotation") S3method("as.Annotation", "Annotation") S3method("as.Annotation", "Span") S3method("[", "Annotation") ## S3method("[<-", "Annotation") S3method("[[", "Annotation") ## S3method("[[<-", "Annotation") S3method("$<-", "Annotation") S3method("as.data.frame", "Annotation") S3method("as.list", "Annotation") S3method("c", "Annotation") S3method("duplicated", "Annotation") S3method("format", "Annotation") S3method("length", "Annotation") S3method("merge", "Annotation") S3method("meta", "Annotation", .get_meta_if_attr) S3method("meta<-", "Annotation", .set_meta_if_attr) S3method("names", "Annotation") S3method("print", "Annotation", .print_via_format) S3method("subset", "Annotation") S3method("unique", "Annotation") export("annotations_in_spans", "features") export("annotate") export("Annotator") S3method("format", "Annotator") S3method("meta", "Annotator", .get_meta_if_attr) S3method("meta<-", "Annotator", .set_meta_if_attr) S3method("print", "Annotator", .print_via_format) export("Simple_Para_Token_Annotator", "Simple_Sent_Token_Annotator", "Simple_Word_Token_Annotator", "Simple_POS_Tag_Annotator", "Simple_Entity_Annotator", "Simple_Chunk_Annotator", "Simple_Stem_Annotator") export("Annotator_Pipeline", "as.Annotator_Pipeline") S3method("as.Annotator_Pipeline", "Annotator_Pipeline") S3method("as.Annotator_Pipeline", "Annotator") S3method("as.Annotator_Pipeline", "list") S3method("[", "Annotator_Pipeline") S3method("as.list", "Annotator_Pipeline") S3method("c", "Annotator_Pipeline") S3method("format", "Annotator_Pipeline") S3method("meta", "Annotator_Pipeline", .get_meta_if_attr) S3method("meta<-", "Annotator_Pipeline", .set_meta_if_attr) S3method("print", "Annotator_Pipeline", .print_via_format) export("next_id", "single_feature") export("Regexp_Tokenizer", "blankline_tokenizer", "whitespace_tokenizer", "wordpunct_tokenizer") export("Tree") S3method("format", "Tree") S3method("print", "Tree", .print_via_format) export("Tree_parse", "Tree_apply") export("words", "sents", "paras", "tagged_words", "tagged_sents", "tagged_paras", "chunked_sents", "parsed_sents", "parsed_paras") S3method("format", "TextDocument", .format_TextDocument) S3method("print", "TextDocument", .print_via_format) export("AnnotatedPlainTextDocument", "annotation") S3method("format", "AnnotatedPlainTextDocument") S3method("print", "AnnotatedPlainTextDocument", .print_via_format) S3method("content", "AnnotatedPlainTextDocument") S3method("content<-", "AnnotatedPlainTextDocument") S3method("meta", "AnnotatedPlainTextDocument", .get_meta_if_slot) S3method("meta<-", "AnnotatedPlainTextDocument", .set_meta_if_slot) S3method("as.character", "AnnotatedPlainTextDocument") S3method("words", "AnnotatedPlainTextDocument") S3method("sents", "AnnotatedPlainTextDocument") S3method("paras", "AnnotatedPlainTextDocument") S3method("tagged_words", "AnnotatedPlainTextDocument") S3method("tagged_sents", "AnnotatedPlainTextDocument") S3method("tagged_paras", "AnnotatedPlainTextDocument") S3method("chunked_sents", "AnnotatedPlainTextDocument") S3method("parsed_sents", "AnnotatedPlainTextDocument") S3method("parsed_paras", "AnnotatedPlainTextDocument") export("CoNLLTextDocument") S3method("format", "CoNLLTextDocument") S3method("print", "CoNLLTextDocument", .print_via_format) S3method("content", "CoNLLTextDocument") S3method("meta", "CoNLLTextDocument", .get_meta_if_slot) S3method("meta<-", "CoNLLTextDocument", .set_meta_if_slot) S3method("as.character", "CoNLLTextDocument") S3method("words", "CoNLLTextDocument") S3method("sents", "CoNLLTextDocument") S3method("tagged_words", "CoNLLTextDocument") S3method("tagged_sents", "CoNLLTextDocument") S3method("chunked_sents", "CoNLLTextDocument") export("CoNLLUTextDocument") S3method("format", "CoNLLUTextDocument") S3method("print", "CoNLLUTextDocument", .print_via_format) S3method("content", "CoNLLUTextDocument") S3method("meta", "CoNLLUTextDocument", .get_meta_if_slot) S3method("meta<-", "CoNLLUTextDocument", .set_meta_if_slot) S3method("as.character", "CoNLLUTextDocument") S3method("words", "CoNLLUTextDocument") S3method("sents", "CoNLLUTextDocument") S3method("tagged_words", "CoNLLUTextDocument") S3method("tagged_sents", "CoNLLUTextDocument") export("TaggedTextDocument") S3method("format", "TaggedTextDocument") S3method("print", "TaggedTextDocument", .print_via_format) S3method("content", "TaggedTextDocument") S3method("meta", "TaggedTextDocument", .get_meta_if_slot) S3method("meta<-", "TaggedTextDocument", .set_meta_if_slot) S3method("as.character", "TaggedTextDocument") S3method("words", "TaggedTextDocument") S3method("sents", "TaggedTextDocument") S3method("paras", "TaggedTextDocument") S3method("tagged_words", "TaggedTextDocument") S3method("tagged_sents", "TaggedTextDocument") S3method("tagged_paras", "TaggedTextDocument") export("WordListDocument") S3method("format", "WordListDocument") S3method("print", "WordListDocument", .print_via_format) S3method("content", "WordListDocument") S3method("meta", "WordListDocument", .get_meta_if_slot) S3method("meta<-", "WordListDocument", .set_meta_if_slot) S3method("as.character", "WordListDocument") S3method("words", "WordListDocument") export("Penn_Treebank_POS_tags") export("Brown_POS_tags") export("Universal_POS_tags") export("Universal_POS_tags_map") export("parse_IETF_language_tag") export("parse_ISO_8601_datetime") S3method("[", "ISO_8601_datetime") S3method("$", "ISO_8601_datetime") S3method("as.Date", "ISO_8601_datetime") S3method("as.POSIXct", "ISO_8601_datetime") S3method("as.POSIXlt", "ISO_8601_datetime") S3method("as.data.frame", "ISO_8601_datetime") S3method("as.matrix", "ISO_8601_datetime") S3method("print", "ISO_8601_datetime") export("ngrams") export("Tagged_Token", "as.Tagged_Token", "is.Tagged_Token") S3method("as.Tagged_Token", "Tagged_Token") S3method("as.Tagged_Token", "TextDocument") S3method("[", "Tagged_Token") ## S3method("[<-", "Tagged_Token") S3method("[[", "Tagged_Token") ## S3method("[[<-", "Tagged_Token") S3method("$<-", "Tagged_Token") S3method("as.data.frame", "Tagged_Token") S3method("as.list", "Tagged_Token") S3method("c", "Tagged_Token") S3method("duplicated", "Tagged_Token") S3method("format", "Tagged_Token") S3method("length", "Tagged_Token") S3method("names", "Tagged_Token") S3method("print", "Tagged_Token", .print_via_format) S3method("unique", "Tagged_Token") export("Span_Tokenizer", "as.Span_Tokenizer", "is.Span_Tokenizer") S3method("as.Span_Tokenizer", "Span_Tokenizer") S3method("as.Span_Tokenizer", "Token_Tokenizer") S3method("as.Span_Tokenizer", "Annotator") S3method("as.Span_Tokenizer", "Annotator_Pipeline") S3method("format", "Span_Tokenizer") S3method("print", "Span_Tokenizer", .print_via_format) S3method("meta", "Span_Tokenizer", .get_meta_if_attr) S3method("meta<-", "Span_Tokenizer", .set_meta_if_attr) export("Token_Tokenizer", "as.Token_Tokenizer", "is.Token_Tokenizer") S3method("as.Token_Tokenizer", "Token_Tokenizer") S3method("as.Token_Tokenizer", "Span_Tokenizer") S3method("as.Token_Tokenizer", "Annotator") S3method("as.Token_Tokenizer", "Annotator_Pipeline") S3method("format", "Token_Tokenizer") S3method("print", "Token_Tokenizer", .print_via_format) S3method("meta", "Token_Tokenizer", .get_meta_if_attr) S3method("meta<-", "Token_Tokenizer", .set_meta_if_attr) S3method("words", "udpipe_connlu") S3method("sents", "udpipe_connlu") S3method("paras", "udpipe_connlu") S3method("tagged_words", "udpipe_connlu") S3method("tagged_sents", "udpipe_connlu") S3method("tagged_paras", "udpipe_connlu") S3method("words", "spacyr_parsed") S3method("sents", "spacyr_parsed") S3method("tagged_words", "spacyr_parsed") S3method("tagged_sents", "spacyr_parsed") S3method("words", "annotation") S3method("sents", "annotation") S3method("paras", "annotation") S3method("tagged_words", "annotation") S3method("tagged_sents", "annotation") S3method("tagged_paras", "annotation") NLP/R/0000755000175100001440000000000013362123103011114 5ustar hornikusersNLP/R/annotation.R0000644000175100001440000002631613362123103013421 0ustar hornikusers## Annotations. ## Conceptually, a single annotation is a quintuple with "slots" id, ## type, start, end and features, and our Annotation objects are ## sequences (to allow positional access) of annotations, i.e., sequence ## of such quintuples. ## The implementation actually uses a "quintuple" (named list of length ## five) with slots giving the respective sequences of slot values. ## The feature slot of a single annotation is a feature map which we ## represent as named lists (at least for now also allowing NULL for an ## empty feature map), hence the sequence of feature values is a list of ## named lists. ## Subscripting via [ extracts subsets of annotations. ## Subscripting via $ extracts one slot value sequence. ## As Annotation objects have all slots of Span objects, we take them to ## have class "Annotation" and also inherit from class "Span". ## We allow for ids to be missing, and Annotation(id = NULL) creates ## missing ids as needed. Annotation_classes <- c("Annotation", "Span") Annotation_slot_names <- c("id", "type", "start", "end", "features") Annotation <- function(id = NULL, type = NULL, start, end, features = NULL, meta = list()) { if(nargs() == 0L) { ## Could also provide default values (e.g., NULL) for all ## arguments ... return(.Annotation_from_args(integer(), character(), integer(), integer(), list(), meta)) } start <- as.integer(start) end <- as.integer(end) n <- length(start) id <- if(is.null(id)) rep.int(NA_integer_, n) else as.integer(id) type <- if(is.null(type)) rep.int(NA_character_, n) else as.character(type) features <- if(is.null(features)) rep.int(list(list()), n) else lapply(features, as.list) ## ## Should perhaps check that all elements of 'features' are named or ## empty lists. ## .Annotation_from_args(id, type, start, end, features, meta) } .Annotation_from_args <- function(id, type, start, end, features, meta) { x <- list(id, type, start, end, features) if(any(diff(lengths(x)) != 0L)) stop("arguments must have the same length") names(x) <- Annotation_slot_names .Annotation_from_list_and_meta(x, meta) } .Annotation_from_list_and_meta <- function(x, meta) { class(x) <- Annotation_classes attr(x, "meta") <- meta x } as.Annotation <- function(x, ...) UseMethod("as.Annotation") as.Annotation.Annotation <- function(x, ...) x as.Annotation.Span <- function(x, id = NULL, type = NULL, ...) { ## Call Annotation() so we get coercion and length checking. Annotation(id, type, x$start, x$end, NULL) } is.Annotation <- function(x) inherits(x, "Annotation") `[.Annotation` <- function(x, i) .Annotation_from_list_and_meta(lapply(unclass(x), `[`, i), attr(x, "meta")) ## ## Implement eventually ... `[<-.Annotation` <- function(x, i, value) .NotYetImplemented() ## `[[.Annotation` <- function(x, i) { y <- lapply(unclass(x), `[[`, i) y$features <- list(y$features) .Annotation_from_list_and_meta(y, attr(x, "meta")) } ## ## Implement eventually ... `[[<-.Annotation` <- function(x, i, value) .NotYetImplemented() ## ## $.Annotation is not really necessary. `$<-.Annotation` <- function(x, name, value) { n <- length(x) x <- unclass(x) if(is.na(pos <- pmatch(name, Annotation_slot_names))) stop("invalid element name") name <- Annotation_slot_names[pos] value <- if(name == "type") as.character(value) else if(name == "features") as.list(value) else as.integer(value) ## This is not very elegant: we could record the slot modes as ## Annotation_slot_modes <- ## c("integer", "character", "integer", "integer", "list") ## but then coercion via the respective as.MODE functions would need ## some trickery ... maybe do this at a later stage, and modify the ## Annotation() creator accordingly. if(length(value) != n) stop("replacement must have the same length as object") x[[pos]] <- value .Annotation_from_list_and_meta(x, attr(x, "meta")) } as.data.frame.Annotation <- function(x, row.names = NULL, optional = FALSE, ...) { y <- data.frame(id = x$id, type = x$type, start = x$start, end = x$end, stringsAsFactors = FALSE, row.names = row.names) y$features <- x$features y } as.list.Annotation <- function(x, ...) lapply(seq_along(x), function(i) x[i]) c.Annotation <- function(..., recursive = FALSE) { args <- lapply(list(...), as.Annotation) meta <- do.call(c, lapply(args, meta)) args <- lapply(args, unclass) y <- lapply(Annotation_slot_names, function(e) unlist(lapply(args, `[[`, e), recursive = FALSE)) names(y) <- Annotation_slot_names ## Remove *exact* duplicates from metadata: if(length(meta)) { meta <- tapply(meta, names(meta), unique, simplify = FALSE) tags <- rep.int(names(meta), lengths(meta)) meta <- unlist(meta, recursive = FALSE, use.names = FALSE) names(meta) <- tags } .Annotation_from_list_and_meta(y, meta) } ## This is at the mercy of duplicated() working well on lists ... duplicated.Annotation <- function(x, incomparables = FALSE, ...) { Reduce(`&`, lapply(unclass(x), duplicated)) } format.Annotation <- function(x, values = TRUE, ...) { if(!length(x)) return(character()) y <- .format_Annotation_without_features(x) wy <- nchar(y[1L], type = "width") wf <- max(16L, 0.95 * getOption("width") - wy) collapse <- format("\n", width = wy + 2L) features <- lapply(x$features, function(e) { if(!(l <- length(e))) return("") s <- if(values) .format_feature_map(e) else names(e) s <- paste0(s, c(rep_len(",", l - 1L), "")) w <- nchar(strwrap(paste(gsub(".", "X", s), collapse = " "), width = wf)) v <- c(0L, head(cumsum(w + 1L), -1L)) f <- v + 1L t <- v + w paste(substring(paste(s, collapse = " "), f, t), collapse = collapse) }) paste0(y, c("features", features), collapse = "\n") } inspect.Annotation <- function(x) { x$features <- vapply(x$features, function(e) { if(length(s <- .format_feature_map(e))) { paste(sprintf("\n %s", s), collapse = "") } else NA_character_ }, "") write.dcf(x, keep.white = "features") } length.Annotation <- function(x) length(x$start) merge.Annotation <- function(x, y, ...) { pos <- match(paste(y$id, y$type, y$start, y$end, sep = "\r"), paste(x$id, x$type, x$start, x$end, sep = "\r"), nomatch = 0L) ## ## This should really combine the unique tag/value pairs. ## In fact, duplicated tags are a problem, but how should they be ## handled (take the pair from x or from y)? x$features[pos] <- Map(c, x$features[pos], y$features[pos > 0L]) ## c(x, y[pos == 0L]) } ## meta.Annotation <- ## function(x, tag = NULL, ...) ## { ## m <- attr(x, "meta") ## if(is.null(tag)) m else m[[tag]] ## } ## `meta<-.Annotation` <- ## function(x, tag = NULL, ..., value) ## { ## if(is.null(tag)) ## attr(x, "meta") <- value ## else ## attr(x, "meta")[[tag]] <- value ## x ## } names.Annotation <- function(x) NULL ## print.Annotation <- ## function(x, values = TRUE, ...) ## { ## writeLines(format(x, values = values)) ## invisible(x) ## } subset.Annotation <- function(x, subset, ...) { e <- substitute(subset) i <- eval(e, unclass(x), parent.frame()) if(!is.logical(i)) stop("'subset' must be logical") i <- i & !is.na(i) x[i] } unique.Annotation <- function(x, incomparables = FALSE, ...) x[!duplicated(x)] .format_Annotation_without_features <- function(x) { sprintf(" %s %s %s %s ", .format_values_with_header(x$id, "id", "right"), .format_values_with_header(x$type, "type", "left"), .format_values_with_header(x$start, "start", "right"), .format_values_with_header(x$end, "end", "right")) } .format_values_with_header <- function(v, h, justify = c("left", "right")) { justify <- match.arg(justify) width <- max(nchar(h), nchar(v)) len <- length(v) fmt <- sprintf("%%%s%ds", c("-", rep.int(if(justify == "left") "-" else "", len)), rep.int(width, len + 1L)) sprintf(fmt, c(h, v)) } ## Try formatting feature maps nicely. ## Similar to what we do in package 'sets', I guess ... .format_feature_map <- function(x, ...) { if(!length(x)) return(character()) sprintf("%s=%s", names(x), vapply(x, .format_feature_value, "")) } ## Formatter for a single value. .format_feature_value <- function(x) { ## Could also make this a generic, which currently seems an ## overkill, in particular if it is not exported so that no one else ## can register methods. if(inherits(x, "Stanford_typed_dependencies")) sprintf("<<%s,%s>>", class(x)[1L], nrow(x)) else if(is.object(x)) sprintf("<<%s>>", class(x)[1L]) else if(is.array(x)) sprintf("<>", paste(dim(x), collapse = ",")) else if(is.character(x) && (length(x) == 1L)) { if(nchar(x) <= 32L) x else "<>" } else if(is.atomic(x) && (length(x) == 1L)) { ## ## Should this take ... args? ## Also, might want to ensure this does not get too long. format(x) ## } else if(is.vector(x)) sprintf("<<%s,%s>>", typeof(x), length(x)) else if(is.null(x)) "NULL" else "<>" } annotations_in_spans <- function(x, y) { y <- as.Span(y) ## An annotation node is contained in a span if it does not start ## ahead of the span and does not end later than the span. ind <- outer(x$start, y$start, ">=") & outer(x$end, y$end, "<=") lapply(seq_len(ncol(ind)), function(j) x[ind[, j]]) } features <- function(x, type = NULL, simplify = TRUE) { if(inherits(x, "AnnotatedPlainTextDocument")) x <- x$annotation else if(!is.Annotation(x)) stop("argument 'x' must be an Annotation object") if(!is.null(type)) { types <- unique(x$type) i <- pmatch(type, types) if(any(is.na(i))) stop("incomplete or invalid 'type'") x <- x[x$type %in% types[i]] } features <- x$features tags <- unique(unlist(lapply(features, names))) y <- lapply(tags, function(tag) lapply(features, `[[`, tag)) if(simplify) y <- lapply(y, .simplify) names(y) <- tags class(y) <- "data.frame" attr(y, "row.names") <- .set_row_names(length(features)) y } .simplify <- function(x) { if((length(len <- unique(lengths(x))) == 1L) && (len == 1L)) unlist(x, recursive = FALSE) else x } NLP/R/ttd.R0000644000175100001440000001163713333632544012056 0ustar hornikusersTaggedTextDocument <- function(con, encoding = "unknown", word_tokenizer = whitespace_tokenizer, sent_tokenizer = Regexp_Tokenizer("\n", invert = TRUE), para_tokenizer = blankline_tokenizer, sep = "/", meta = list()) { s <- String(paste(readLines(con, encoding = encoding, warn = FALSE), collapse = "\n")) paras <- if(!is.null(para_tokenizer)) s[para_tokenizer(s)] else as.character(s) x <- lapply(paras, function(para) { ## Avoid as.String() coercion. spans <- sent_tokenizer(para) sents <- substring(para, spans$start, spans$end) lapply(sents, function(sent) { spans <- word_tokenizer(sent) words <- substring(sent, spans$start, spans$end) toks <- strsplit(words, sep, fixed = TRUE) one <- vapply(toks, `[[`, "", 1L) two <- vapply(toks, `[[`, "", 2L) data.frame(word = one, POS = toupper(two), stringsAsFactors = FALSE) }) }) ## Use sentence ids which are unique across paras. lens <- lapply(x, length) ids <- Map(function(f, l) as.integer(seq.int(from = f, length.out = l)), c(0L, head(cumsum(lens), -1L)) + 1L, lens) x <- Map(function(u, v) { cbind(data.frame(sent = rep.int(u, vapply(v, nrow, 0L))), do.call(rbind, v)) }, ids, x) doc <- list(content = x, meta = meta) class(doc) <- c("TaggedTextDocument", "TextDocument") doc } format.TaggedTextDocument <- function(x, ...) { content <- x$content len <- length(content) c(.format_TextDocument(x), sprintf("Content: words: %d, sents: %d, paras: %d", sum(vapply(content, NROW, 0L)), tail(content[[len]]$sent, 1L), len)) } ## print.TaggedTextDocument <- ## function(x, ...) ## { ## content <- x$content ## len <- length(content) ## writeLines(sprintf("<>", ## sum(vapply(content, NROW, 0L)), ## tail(content[[len]]$sent, 1L), ## len)) ## invisible(x) ## } content.TaggedTextDocument <- function(x) x$content ## meta.TaggedTextDocument <- ## function(x, tag = NULL, ...) ## if(is.null(tag)) x$meta else x$meta[[tag]] ## `meta<-.TaggedTextDocument` <- ## function(x, tag = NULL, ..., value) ## { ## if(is.null(tag)) ## x$meta <- value ## else ## x$meta[[tag]] <- value ## x ## } ## ## It would be nice if the as.character() method could "suitably" ## detokenize the word tokens into sentences. But this requires ## (a) knowing at least the language of the text ## (b) having code to detokenize when knowing the language ... ## as.character.TaggedTextDocument <- words.TaggedTextDocument <- function(x, ...) { unlist(lapply(x$content, `[[`, "word")) } ## ## Could more simply do ## sents.TaggedTextDocument <- function(x, ...) ## unlist(paras(x), recursive = FALSE) ## sents.TaggedTextDocument <- function(x, ...) { unlist(lapply(x$content, function(e) split(e$word, e$sent)), recursive = FALSE) } paras.TaggedTextDocument <- function(x, ...) { lapply(x$content, function(e) split(e$word, e$sent)) } tagged_words.TaggedTextDocument <- function(x, map = NULL, ...) { if(!is.null(map)) { x <- .map_POS_tags_TaggedTextDocument(x, map) } Tagged_Token(unlist(lapply(x$content, `[[`, "word")), unlist(lapply(x$content, `[[`, "POS"))) } ## ## Could more simply do ## tagged_sents.TaggedTextDocument <- function(x, ...) ## unlist(tagged_paras(x), recursive = FALSE) ## tagged_sents.TaggedTextDocument <- function(x, map = NULL, ...) { if(!is.null(map)) { x <- .map_POS_tags_TaggedTextDocument(x, map) } unlist(lapply(x$content, function(e) split(Tagged_Token(e$word, e$POS), e$sent)), recursive = FALSE) } tagged_paras.TaggedTextDocument <- function(x, map = NULL, ...) { if(!is.null(map)) { x <- .map_POS_tags_TaggedTextDocument(x, map) } lapply(x$content, function(e) split(Tagged_Token(e$word, e$POS), e$sent)) } .map_POS_tags_TaggedTextDocument <- function(x, map) { map <- POS_tag_mapper(map, meta(x, "POS_tagset")) x$content <- lapply(x$content, function(e) { e$POS <- map(e$POS) e }) x } NLP/R/utils.R0000644000175100001440000000145612521153333012411 0ustar hornikusers### Format and print. .format_TextDocument <- function(x, ...) c(sprintf("<<%s>>", class(x)[1L]), sprintf("Metadata: %d", length(meta(x)))) .print_via_format <- function(x, ...) { writeLines(format(x, ...)) invisible(x) } ### Get and set metadata. .get_meta_if_attr <- function(x, tag = NULL, ...) { m <- attr(x, "meta") if(is.null(tag)) m else m[[tag]] } .set_meta_if_attr <- function(x, tag = NULL, ..., value) { if(is.null(tag)) attr(x, "meta") <- value else attr(x, "meta")[[tag]] <- value x } .get_meta_if_slot <- function(x, tag = NULL, ...) if(is.null(tag)) x$meta else x$meta[[tag]] .set_meta_if_slot <- function(x, tag = NULL, ..., value) { if(is.null(tag)) x$meta <- value else x$meta[[tag]] <- value x } NLP/R/string.R0000644000175100001440000000470413334576423012572 0ustar hornikusers## A simple string class. String <- function(x) { .String_from_string(as.character(x)[[1L]]) } ## Note subscripting by [[: this insists on the first element, and ## hence gives an error instead of NA_character_ if there is none. as.String <- function(x) UseMethod("as.String") as.String.String <- identity as.String.default <- function(x) String(paste(x, collapse = "\n")) is.String <- function(x) inherits(x, "String") print.String <- function(x, ...) writeLines(x) ## Provide a '[' method performing slicing (as we cannot provide S3 ## methods for substr, and clearly substrings of strings should be ## strings. ## Note that we have no distinction between spans and span arrays (same ## issue as having no distinction between strings and string arrays in ## base R). Hence, we take spans to always operate in an array context ## (for now: we could add a drop = FALSE argument to have subscripting ## turn character vectors of length one back to strings again). `[.String` <- function(x, i, j) { mysubstring <- function(x, i, j) { ## substring() recycles to max length of args only when this is ## positive. if(!length(i)) character() else substring(x, i, j) } if(missing(j)) { if(is.Span(i)) return(mysubstring(x, i$start, i$end)) if(is.list(i)) { if(!length(i)) return(list()) else if(all(vapply(i, is.Span, NA))) return(lapply(i, function(e) mysubstring(x, e$start, e$end))) } } ## Regular slicing operators in a scalar context. String(substr(x, i, j)) } ## More methods? ## ## A popular mailing list discussion item is to use a Java style '+' ## operator for concatenating strings (not uniformly liked as the ## corresponding operation is not commutative): `+.String` <- function(e1, e2) .String_from_string(paste0(as.String(e1), as.String(e2))) ## Also provide Python-style string repetition. `*.String` <- function(e1, e2) { if(is.numeric(e1) && (length(e1) == 1L)) .String_from_string(paste(rep.int(e2, e1), collapse = "")) else if(is.numeric(e2) && (length(e2) == 1L)) .String_from_string(paste(rep.int(e1, e2), collapse = "")) else stop("Invalid operands.") } ## What about c.String? .String_from_string <- function(x) { y <- enc2utf8(x) class(y) <- "String" y } NLP/R/tokenize.R0000644000175100001440000001365313334313212013100 0ustar hornikusers## Tokenizers break text up into words, phrases, symbols, or other ## meaningful elements called tokens, see e.g. ## . ## This can be accomplished by returning the sequence of tokens, or the ## corresponding spans (character start and end positions). ## Apache OpenNLP provides a Tokenizer interface, with methods ## String[] tokenize() and Span[] tokenizePos() for the two variants. ## See e.g. ## . ## NLTK provides an interface class nltk.tokenize.api.TokenizerI, for ## which subclasses must define a tokenize() method, and can define a ## span_tokenize() method. ## See e.g. . ## In R, this could be mimicked by having two generics for getting the ## tokens or spans, and have a virtual Tokenizer class for which ## extension classes must provide methods for at least one of the ## generics. ## However, it seems more natural to have tokenizers be *functions* ## (instead of interface classes) which can be called directly (instead ## of calling the respective generics), and have two "kinds" of such ## functions: token tokenizers and span tokenizers. We use the class ## information to indicate the kind, which in turn allows to provide a ## generic mechanism for mapping between the two kinds (straightforward ## when going from spans to tokens, doable for the opposite direction). ## This also allows to "extract" both kinds of tokenizers from suitable ## annotators or annotator pipelines. ## For now, there is no underlying virtual Tokenizer class. ### * Span tokenizers Span_Tokenizer <- function(f, meta = list()) { attr(f, "meta") <- meta class(f) <- "Span_Tokenizer" f } as.Span_Tokenizer <- function(x, ...) UseMethod("as.Span_Tokenizer") as.Span_Tokenizer.Span_Tokenizer <- function(x, ...) x ## For now, pass metadata as is. as.Span_Tokenizer.Token_Tokenizer <- function(x, ...) { f <- function(s) { s <- as.String(s) spans_from_tokens(s, x(s)) } Span_Tokenizer(f, meta(x)) } ## For now, do not pass metadata. as.Span_Tokenizer.Annotator <- as.Span_Tokenizer.Annotator_Pipeline <- function(x, type = "word", ...) { f <- function(s) { a <- x(as.String(s)) as.Span(a[a$type == "word", ]) } Span_Tokenizer(f) } is.Span_Tokenizer <- function(x) inherits(x, "Span_Tokenizer") format.Span_Tokenizer <- function(x, ...) { d <- meta(x, "description") if(is.null(d)) { "A span tokenizer." } else { c("A span tokenizer, with description", strwrap(d, indent = 2L, exdent = 2L)) } } ### * Token tokenizers Token_Tokenizer <- function(f, meta = list()) { attr(f, "meta") <- meta class(f) <- "Token_Tokenizer" f } as.Token_Tokenizer <- function(x, ...) UseMethod("as.Token_Tokenizer") as.Token_Tokenizer.Token_Tokenizer <- function(x, ...) x ## For now, pass metadata as is. as.Token_Tokenizer.Span_Tokenizer <- function(x, ...) { f <- function(s) { s <- as.String(s) s[x(s)] } Token_Tokenizer(f, meta(x)) } ## For now, do not pass metadata. as.Token_Tokenizer.Annotator <- as.Token_Tokenizer.Annotator_Pipeline <- function(x, type = "word", ...) { f <- function(s) { s <- as.String(s) a <- x(s) s[a[a$type == "word", ]] } Token_Tokenizer(f) } is.Token_Tokenizer <- function(x) inherits(x, "Token_Tokenizer") format.Token_Tokenizer <- function(x, ...) { d <- meta(x, "description") if(is.null(d)) { "A token tokenizer." } else { c("A token tokenizer, with description", strwrap(d, indent = 2L, exdent = 2L)) } } ### Regexp span tokenizers a la NLTK. Regexp_Tokenizer <- function(pattern, invert = FALSE, ..., meta = list()) { force(pattern) args <- list(...) f <- if(invert) { ## Pattern gives the separators. function(s) { s <- as.String(s) if(is.na(s) || !nchar(s)) stop("Need a non-empty string.") m <- do.call(gregexpr, c(list(pattern = pattern, text = s), args))[[1L]] if((length(m) == 1L) && (m == -1L)) return(Span(1L, nchar(s))) start <- c(1L, m + attr(m, "match.length")) end <- c(m - 1L, nchar(s)) ind <- start <= end Span(start[ind], end[ind]) } } else { ## Pattern gives the tokens. function(s) { s <- as.String(s) if(is.na(s) || !nchar(s)) stop("Need a non-empty string.") m <- do.call(gregexpr, c(list(pattern = pattern, text = s), args))[[1L]] Span(m, m + attr(m, "match.length") - 1L) } } Span_Tokenizer(f, meta) } whitespace_tokenizer <- Regexp_Tokenizer("\\s+", invert = TRUE, meta = list(description = "Divides strings into substrings by treating any sequence of whitespace characters as a separator.")) blankline_tokenizer <- Regexp_Tokenizer("\\s*\n\\s*\\n\\s*", invert = TRUE, meta = list(description = "Divides strings into substrings by treating any sequence of blank lines as a separator.")) wordpunct_tokenizer <- Regexp_Tokenizer("\\w+|[^\\w\\s]+", perl = TRUE, meta = list(description = "Divides strings into substrings of alphabetic and (non-whitespace) non-alphabetic characters.")) ### * Utilities spans_from_tokens <- function(x, tokens) { start <- end <- integer(length(tokens)) off <- 0L for(i in seq_along(tokens)) { m <- regexpr(tokens[i], x, fixed = TRUE) pos <- m + attr(m, "match.length") x <- substring(x, pos) start[i] <- off + m end[i] <- off <- off + pos - 1L } Span(start, end) } NLP/R/tnt.R0000644000175100001440000000613112517713330012055 0ustar hornikusers## A simple class for storing tokens and tags ("tagged tokens"). ## Conceptually, a single tagged token is a token/tag pair and our ## Tagged_Token objects are sequences (to allow positional access) of ## tagged tokens, i.e., sequences of pairs. ## The implementation actually uses a "pair" (named list of length two) ## of "slots" giving the token and tag sequences. ## Subscripting via [ extracts subsets of tagged tokens. ## Subscripting via $ extracts one slot. Tagged_Token_slot_names <- c("token", "tag") Tagged_Token <- function(token, tag) { token <- as.character(token) tag <- as.character(tag) if(length(token) != length(tag)) stop("arguments must have the same length") .Tagged_Token_from_args(token, tag) } .Tagged_Token_from_args <- function(token, tag) { x <- list(token, tag) names(x) <- Tagged_Token_slot_names .Tagged_Token_from_list(x) } .Tagged_Token_from_list <- function(x) { class(x) <- "Tagged_Token" x } as.Tagged_Token <- function(x) UseMethod("as.Tagged_Token") as.Tagged_Token.Tagged_Token <- identity ## ## Should this get a '...'? (And hence the generic, too?) as.Tagged_Token.TextDocument <- function(x) tagged_words(x) ## is.Tagged_Token <- function(x) inherits(x, "Tagged_Token") `[.Tagged_Token` <- function(x, i) .Tagged_Token_from_list(lapply(unclass(x), `[`, i)) ## ## Implement eventually ... `[<-.Tagged_Token` <- function(x, i, value) .NotYetImplemented() ## `[[.Tagged_Token` <- function(x, i) .Tagged_Token_from_list(lapply(unclass(x), `[[`, i)) ## ## Implement eventually ... `[[<-.Tagged_Token` <- function(x, i, value) .NotYetImplemented() ## ## $.Tagged_Token is not really necessary. `$<-.Tagged_Token` <- function(x, name, value) { n <- length(x) x <- unclass(x) if(is.na(pos <- pmatch(name, Tagged_Token_slot_names))) stop("invalid element name") value <- as.integer(value) if(length(value) != n) stop("replacement must have the same length as object") x[[pos]] <- value .Tagged_Token_from_list(x) } as.data.frame.Tagged_Token <- function(x, row.names = NULL, optional = FALSE, ...) { data.frame(token = x$token, tag = x$tag, row.names = row.names) } as.list.Tagged_Token <- function(x, ...) lapply(seq_along(x), function(i) x[i]) c.Tagged_Token <- function(..., recursive = FALSE) { args <- lapply(list(...), function(e) unclass(as.Tagged_Token(e))) y <- lapply(Tagged_Token_slot_names, function(e) unlist(lapply(args, `[[`, e))) names(y) <- Tagged_Token_slot_names .Tagged_Token_from_list(y) } duplicated.Tagged_Token <- function(x, incomparables = FALSE, ...) { do.call(`&`, lapply(unclass(x), duplicated)) } format.Tagged_Token <- function(x, ...) { sprintf("%s/%s", x$token, x$tag) } length.Tagged_Token <- function(x) length(x$token) names.Tagged_Token <- function(x) NULL ## print.Tagged_Token <- ## function(x, ...) ## { ## print(format(x, ...)) ## invisible(x) ## } unique.Tagged_Token <- function(x, incomparables = FALSE, ...) x[!duplicated(x)] NLP/R/conllu.R0000644000175100001440000000763713144532262012560 0ustar hornikusers## See . CoNLLUTextDocument <- function(con, meta = list()) { lines <- readLines(con, encoding = "UTF-8") ind_b <- lines == "" ind_c <- startsWith(lines, "#") ind <- !ind_b & !ind_c ## Now using scan(text = lines[ind]) to read in the records is ## possible but unbearably slow for large documents: instead, try to ## proceed "directly". ## records <- strsplit(lines[ind], "\t", fixed = TRUE) ## records <- as.data.frame(do.call(rbind, records), ## stringsAsFactors = FALSE) ## names(records) <- ## c("ID", "FORM", "LEMMA", "UPOSTAG", "XPOSTAG", "FEATS", "HEAD", ## "DEPREL", "DEPS", "MISC") ## sent <- cumsum(ind_b) + 1L ## tab <- cbind(data.frame(sent = sent), ## as.data.frame(do.call(cbind, records), ## stringsAsFactors = FALSE))[ind , ] sent <- cumsum(ind_b) + 1L tab <- cbind(data.frame(sent[ind]), as.data.frame(do.call(rbind, strsplit(lines[ind], "\t", fixed = TRUE)), stringsAsFactors = FALSE)) names(tab) <- c("sent", "ID", "FORM", "LEMMA", "UPOSTAG", "XPOSTAG", "FEATS", "HEAD", "DEPREL", "DEPS", "MISC") comments <- split(lines[ind_c], sent[ind_c]) attr(tab, "comments") <- comments ## From CoNLL-U v2 on 'sent_id' and 'text' comments are compulsory ## for every sentence. Be defensive and add these as attributes ## only if always available. ind <- startsWith("# sent_id =", lines) if(all(diff(sent[ind]) == 1)) attr(tab, "sent_id") <- sub("^# sent_id = *", "", lines[ind]) ind <- startsWith("# text =", lines) if(all(diff(sent[ind]) == 1)) attr(tab, "text") <- sub("^# text = *", "", lines[ind]) doc <- list(content = tab, meta = meta) class(doc) <- c("CoNLLUTextDocument", "TextDocument") doc } ## CoNLL-U allows to represent both words and (multiword) tokens, which ## both have FORM entries, with ID single integers for words and integer ## ranges for the tokens. We provide the tokens with as.character() and ## the words with the other "viewers", in particular, words(). format.CoNLLUTextDocument <- function(x, ...) { y <- x$content ind <- !grepl("[.-]", y$ID) c(.format_TextDocument(x), sprintf("Content: words: %d, sents: %d", sum(ind), y[NROW(y), "sent"])) } content.CoNLLUTextDocument <- function(x) x$content as.character.CoNLLUTextDocument <- function(x, ...) { y <- x$content ## Drop empty nodes. y <- y[!grepl(".", y$ID, fixed = TRUE), ] ## Expand ranges to determine forms to be skipped for tokens. ind <- grepl("-", y$ID, fixed = TRUE) ids <- y$ID[ind] skip <- Map(seq, sub("-.*", "", ids), sub(".*-", "", ids)) skip <- paste(rep.int(y$sent[ind], lengths(skip)), unlist(skip), sep = ".") y$FORM[is.na(match(paste(y$sent, y$ID, sep = "."), skip))] } words.CoNLLUTextDocument <- function(x, ...) { ind <- !grepl("[.-]", x$content$ID) x$content$FORM[ind] } sents.CoNLLUTextDocument <- function(x, ...) { ind <- !grepl("[.-]", x$content$ID) split(x$content$FORM[ind], x$content$sent[ind]) } tagged_words.CoNLLUTextDocument <- function(x, which = c("UPOSTAG", "XPOSTAG"), ...) { which <- match.arg(which) ind <- !grepl("[.-]", x$content$ID) Tagged_Token(x$content$FORM[ind], x$content[[which]][ind]) } tagged_sents.CoNLLUTextDocument <- function(x, which = c("UPOSTAG", "XPOSTAG"), ...) { which <- match.arg(which) ind <- !grepl("[.-]", x$content$ID) split(Tagged_Token(x$content$FORM[ind], x$content[[which]][ind]), x$content$sent[ind]) } NLP/R/sysdata.rda0000644000175100001440000026360413362123144013274 0ustar hornikusers7zXZi"6!X])TW"nRʟOqcWK>&L$].B'b_D &s8KέR;?O^_Qe/l/~ʓԜ2?ł'BU|}Vu{)=f1JlwUZ^` ,9*t=4#E/ L{\SR)Rae1 jJ3)&(a:n#!9OJjjʊosS2iR{3dBy ;CR[~h]w;^%0yn/.LUDY.a+0=tWY4WkWCsCqXL<(l,8-LnK%ٳF^Y4偈֤V5`ں5YJ%]/i*~vJTqGG9WSw>?Jq>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qb+/Bh:ȉ5+v/jZ} ~~_+Twc zBQlx@sg{\T};M1Vj|!ZCdT٘QR^11QBpts!dx ɝ5?)?\aC:Z^-ũdb!ն$MrZ^bA"T<r܆31<\6yIV k2)0k(^;_e ;"F. n$:\dS 85`Ҡ*Lū_(#[DPOoү6Hd-c! -$\5"”N~ =ULBt'\**QӧM%\` a|b EHxeau⸚y!9_aUEeOSh{BH>hAїf AAB&@)Y}."h9+~C<OHNl4fJim 4sn :~ jE },~?pB&eQc0J^=XsQ뭹NjUFuuTWDg_B_Al k12$ ÄΏCk>Y售>~:7Jc-dy!maD@ xt}XWY؞-gDTHS_6Pe+)L;4lw=yצJ` u^آ"{BB6!w>FMŬGv@B B&!H/jrT̽Q_p}L)W}Ail>c(Ӡ3%i!&:`ow}?rw];|e;I 6-|lf>Aqe& ЃPf ʠ)Yz\z@| `Zt)4Wp3X@.U;I^3 g.ay $kTn~t5Z&/KIRhOK\4|`ZL>ZwT;J;1i\` zs JǬًt< ~=U3"qᢛ28I^2qIF%2':@#< F%Cz+ߕ¢ei᠊aezVEϿx%|ZMrCN22a\45[衕v41k>'`VbYn+b:=/=NV2'',M0x^t~Jo In଩pUA٧4:f+bu`H0Jf^ͳ pqDҚhNM[TQ[*`k{#DhDsE-)oJtϤ  q}R, : :hS W߲1+rX>CnU@a(pү爳:L]zJCi "z_)eJo^[sc*+./@^|("]o2KN'R`q[UȚn_7^ ĞqAVm\[UQCs0FfRh/ F ȶ$ss1..6/̊fnMWYsIjY>0 YZNLP/R/conll.R0000644000175100001440000001136513143571336012370 0ustar hornikusersCoNLLTextDocument <- function(con, encoding = "unknown", format = "conll00", meta = list()) { if(length(format) == 1L) { format <- switch(format, conll00 = c(WORD = "WORD", POS = "POS", CHUNK = "CHUNK"), conll01 = c(WORD = "WORD", POS = "POS", CHUNK = "CHUNK", "CLAUSE"), conll02 = c(WORD = "WORD", NE = "NE"), ## conll03 would have different fields for the German ## variant conllx = c("ID", WORD = "FORM", "LEMMA", POS = "CPOSTAG", "POSTAG", "FEATS", "HEAD", "DEPREL", "PHEAD", "PDEPREL"), ## Corresponding to CoNLL X (10) from 2006, also used ## for conll07 conll09 = c("ID", WORD = "FORM", "LEMMA", "PLEMMA", POS = "POS", "PPOS", "FEAT", "PFEAT", "HEAD", "PHEAD", "DEPREL", "PDEPREL", "FILLPRED", "PRED", "APREDs")) } records <- scan(con, what = rep.int(list(""), length(format)), encoding = encoding, quote = NULL, quiet = TRUE, fill = TRUE, blank.lines.skip = FALSE) names(records) <- format ind <- (records[[1L]] == "") tab <- cbind(data.frame(sent = cumsum(ind) + 1L), as.data.frame(do.call(cbind, records), stringsAsFactors = FALSE))[!ind, ] attr(tab, "format") <- c("sent", format) doc <- list(content = tab, meta = meta) class(doc) <- c("CoNLLTextDocument", "TextDocument") doc } format.CoNLLTextDocument <- function(x, ...) { content <- x$content nr <- NROW(content) c(.format_TextDocument(x), sprintf("Content: words: %d, sents: %d", nr, content[[nr, "sent"]])) } ## print.CoNLLTextDocument <- ## function(x, ...) ## { ## content <- x$content ## nr <- NROW(content) ## writeLines(sprintf("<>", ## nr, content[[nr, "sent"]])) ## invisible(x) ## } content.CoNLLTextDocument <- function(x) x$content ## meta.CoNLLTextDocument <- ## function(x, tag = NULL, ...) ## if(is.null(tag)) x$meta else x$meta[[tag]] ## `meta<-.CoNLLTextDocument` <- ## function(x, tag = NULL, ..., value) ## { ## if(is.null(tag)) ## x$meta <- value ## else ## x$meta[[tag]] <- value ## x ## } as.character.CoNLLTextDocument <- words.CoNLLTextDocument <- function(x, ...) { fmt <- attr(x$content, "format") pos <- .position_of_field(fmt, "WORD") x$content[[pos]] } sents.CoNLLTextDocument <- function(x, ...) { fmt <- attr(x$content, "format") pos <- .position_of_field(fmt, "WORD") split(x$content[[pos]], x$content$sent) } tagged_words.CoNLLTextDocument <- function(x, map = NULL, ...) { if(!is.null(map)) x <- .map_POS_tags_CoNLLTextDocument(x, map) fmt <- attr(x$content, "format") pos_W <- .position_of_field(fmt, "WORD") pos_P <- .position_of_field(fmt, "POS") Tagged_Token(x$content[[pos_W]], x$content[[pos_P]]) } tagged_sents.CoNLLTextDocument <- function(x, map = NULL, ...) { if(!is.null(map)) x <- .map_POS_tags_CoNLLTextDocument(x, map) fmt <- attr(x$content, "format") pos_W <- .position_of_field(fmt, "WORD") pos_P <- .position_of_field(fmt, "POS") split(Tagged_Token(x$content[[pos_W]], x$content[[pos_P]]), x$content$sent) } chunked_sents.CoNLLTextDocument <- function(x, ...) { fmt <- attr(x$content, "format") pos_W <- .position_of_field(fmt, "WORD") pos_P <- .position_of_field(fmt, "POS") pos_C <- .position_of_field(fmt, "CHUNK") Map(chunk_tree_from_chunk_info, split(x$content[[pos_W]], x$content$sent), split(x$content[[pos_P]], x$content$sent), split(x$content[[pos_C]], x$content$sent)) } .map_POS_tags_CoNLLTextDocument <- function(x, map) { map <- POS_tag_mapper(map, meta(x, "POS_tagset")) fmt <- attr(x$content, "format") pos <- .position_of_field(fmt, "POS") x$content[[pos]] <- map(x$content[[pos]]) x } .position_of_field <- function(fmt, kind) { pos <- which(names(fmt) == kind) if(length(pos) != 1L) stop(gettextf("Cannot determine position of '%s'", kind), call. = FALSE, domain = NA) pos } NLP/R/generics.R0000644000175100001440000000040012314326274013042 0ustar hornikuserscontent <- function(x) UseMethod("content", x) `content<-` <- function(x, value) UseMethod("content<-", x) meta <- function(x, tag = NULL, ...) UseMethod("meta", x) `meta<-` <- function(x, tag = NULL, ..., value) UseMethod("meta<-", x) NLP/R/udpipe.R0000644000175100001440000000262413337763133012550 0ustar hornikusers## Viewer methods for objects of class "udpipe_connlu" as obtained by ## udpipe::udpipe_annotate(). ## ## All methods will need the udpipe namespace loaded to use the ## as.data.frame() method for class "udpipe_connlu". ## Should we check for this? ## Perhaps simply call loadNamespace("udpipe") in the methods? ## words.udpipe_connlu <- function(x, ...) { x <- as.data.frame(x) x$token } sents.udpipe_connlu <- function(x, ...) { x <- as.data.frame(x) split(x$token, x$sentence_id) } paras.udpipe_connlu <- function(x, ...) { x <- as.data.frame(x) lapply(split(x, x$paragraph_id), function(e) split(e$token, e$sentence_id)) } tagged_words.udpipe_connlu <- function(x, which = c("upos", "xpos"), ...) { x <- as.data.frame(x) which <- match.arg(which) Tagged_Token(x$token, x[[which]]) } tagged_sents.udpipe_connlu <- function(x, which = c("upos", "xpos"), ...) { x <- as.data.frame(x) which <- match.arg(which) .tagged_sents_from_conllu_frame(x, which) } .tagged_sents_from_conllu_frame <- function(x, which) { lapply(split(x, x$sentence_id), function(e) Tagged_Token(e$token, e[[which]])) } tagged_paras.udpipe_connlu <- function(x, which = c("upos", "xpos"), ...) { x <- as.data.frame(x) which <- match.arg(which) lapply(split(x, x$paragraph_id), .tagged_sents_from_conllu_frame, which) } NLP/R/viewers.R0000644000175100001440000000205512503572502012734 0ustar hornikuserswords <- function(x, ...) UseMethod("words") sents <- function(x, ...) UseMethod("sents") paras <- function(x, ...) UseMethod("paras") tagged_words <- function(x, ...) UseMethod("tagged_words") tagged_sents <- function(x, ...) UseMethod("tagged_sents") tagged_paras <- function(x, ...) UseMethod("tagged_paras") chunked_sents <- function(x, ...) UseMethod("chunked_sents") parsed_sents <- function(x, ...) UseMethod("parsed_sents") parsed_paras <- function(x, ...) UseMethod("parsed_paras") chunk_tree_from_chunk_info <- function(words, ptags, ctags) { ind <- grepl("^[BO]", ctags) ## ## Should this also use Tagged_Token()? chunks <- split(sprintf("%s/%s", words, ptags), cumsum(ind)) ## nms <- sub(".*-", "", ctags[ind]) ind <- nms != "O" chunks[ind] <- Map(Tree, nms[ind], chunks[ind]) Tree("S", chunks) } POS_tag_mapper <- function(map, set) { if(is.function(map)) return(map) if(is.list(map)) map <- map[[set]] function(pos) map[pos] } NLP/R/cleannlp.R0000644000175100001440000000251713337767237013070 0ustar hornikusers## Viewer methods for objects of class "annotation" as obtained by ## cleanNLP::cnlp_annotate(). words.annotation <- function(x, ...) { x <- cleanNLP::cnlp_get_token(x) x$word } sents.annotation <- function(x, ...) { x <- cleanNLP::cnlp_get_token(x) split(x$word, x$sid) } paras.annotation <- function(x, ...) { x <- cleanNLP::cnlp_get_token(x) if(is.na(match("pid", names(x)))) stop("unavailable paragraph ids") lapply(split(x, x$pid), function(e) split(e$word, e$sid)) } tagged_words.annotation <- function(x, which = c("upos", "pos"), ...) { x <- cleanNLP::cnlp_get_token(x) which <- match.arg(which) Tagged_Token(x$word, x[[which]]) } tagged_sents.annotation <- function(x, which = c("upos", "pos"), ...) { x <- cleanNLP::cnlp_get_token(x) which <- match.arg(which) .tagged_sents_from_cnlp_token_frame(x, which) } .tagged_sents_from_cnlp_token_frame <- function(x, which) { lapply(split(x, x$sid), function(e) Tagged_Token(e$word, e[[which]])) } tagged_paras.annotation <- function(x, which = c("upos", "pos"), ...) { x <- cleanNLP::cnlp_get_token(x) if(is.na(match("pid", names(x)))) stop("unavailable paragraph ids") which <- match.arg(which) lapply(split(x, x$pid), .tagged_sents_from_cnlp_token_frame, which) } NLP/R/language.R0000644000175100001440000002314213334312770013035 0ustar hornikusersparse_IETF_language_tag <- function(x, expand = FALSE) { n <- length(x) y <- rep.int(list(character()), n) names(y) <- x ## How nice should we be? ## Allow for empty or missing elements ... pos <- seq_along(x) if(any(ind <- (is.na(x) | (x == "")))) { pos <- pos[!ind] x <- x[pos] } ## See . ## Language tags can be of the form (in ABNF, see ## ): ## langtag / privateuse / grandfathered ## where ## privateuse = ("x"/"X") 1*("-" (1*8alphanum)) ## grandfathered = 1*3ALPHA 1*2("-" (2*8alphanum)) re_privateuse <- "[xX]((-[[:alnum:]]{1,8}){1,})" ## Grandfathered tags must really be determined by exact matching. ind <- !is.na(match(x, IANA_language_subtag_registry_grandfathered_table$Tag)) if(any(ind)) { y[pos[ind]] <- as.list(sprintf("Grandfathered=%s", x[ind])) x[ind] <- "" pos <- pos[!ind] } if(length(pos)) { pat <- sprintf("^%s$", re_privateuse) ind <- grepl(pat, x, perl = TRUE) if(any(ind)) { y[pos[ind]] <- as.list(sprintf("Privateuse=%s", substring(x[ind], 3L))) x[ind] <- "" pos <- pos[!ind] } } ## Now for the real thing. ## Remaining tags should now be as follows: ## (language ## ["-" script] ## ["-" region] ## *(["-" variant]) ## *(["-" extension]) ## ["-" privateuse] ## where ## language = (2*3ALPHA [-extlang]) ; shortest ISO 639 code ## / 4ALPHA ; reserved for future use ## / 5*8ALPHA ; registered language subtag ## extlang = *3("-" 3*ALPHA) ; reserved for future use ## script = 4ALPHA ; ISO 15924 code ## region = 2ALPHA ; ISO 3166 code ## / 3DIGIT ; UN M.49 code ## variant = 5*8alphanum ; registered variants ## / (DIGIT 3alphanum) ## extension = singleton 1*("-" (2*8alphanum)) ## singleton = %x41-57 / %x59-5A / %x61-77 / %x79-7A / DIGIT ## ; "a"-"w" / "y"-"z" / "A"-"W" / "Y"-"Z" / "0"-"9" ## We handle language/extlang a bit differently (more generously). re_extlang <- "[[:alpha:]]{3}" re_language <- sprintf("[[:alpha:]]{2,3}(-%s){0,3}|[[:alpha:]]{4,8}", re_extlang) re_script <- "[[:alpha:]]{4}" re_region <- "[[:alpha:]]{2}|[[:digit:]]{3}" re_variant <- "[[:alnum:]]{5,8}|[[:digit:]][[:alnum:]]{3}" re_singleton <- "[abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ0123456789]" re_extension <- sprintf("(%s)(-[[:alnum:]]{2,8}){1,}", re_singleton) bad <- integer() if(length(pos)) { pat <- sprintf("^(%s)(-.*|$)", re_language) ind <- grepl(pat, x, perl = TRUE) if(!all(ind)) { bad <- which(!ind) x[bad] <- "" } y[pos[ind]] <- lapply(strsplit(sub(pat, "\\1", x[ind], perl = TRUE), "-", fixed = TRUE), function(e) { c(sprintf("Language=%s", e[1L]), sprintf("Extension=%s", e[-1L])) }) x[ind] <- sub(pat, "\\3", x[ind], perl = TRUE) ind <- nzchar(x) pos <- pos[ind] x <- x[ind] } if(length(pos)) { repeat { ## Use a loop so that we can finally stop when done. ## Script. pat <- sprintf("^-(%s)(-.*|$)", re_script) if(any(ind <- grepl(pat, x, perl = TRUE))) { y[pos[ind]] <- Map(c, y[pos[ind]], sprintf("Script=%s", sub(pat, "\\1", x[ind], perl = TRUE))) x[ind] <- sub(pat, "\\2", x[ind], perl = TRUE) ind <- nzchar(x) pos <- pos[ind] x <- x[ind] if(!length(x)) break } ## Region. pat <- sprintf("^-(%s)(-.*|$)", re_region) if(any(ind <- grepl(pat, x, perl = TRUE))) { y[pos[ind]] <- Map(c, y[pos[ind]], sprintf("Region=%s", sub(pat, "\\1", x[ind], perl = TRUE))) x[ind] <- sub(pat, "\\2", x[ind], perl = TRUE) ind <- nzchar(x) pos <- pos[ind] x <- x[ind] if(!length(x)) break } ## Variant(s). pat <- sprintf("^-(%s)(-.*|$)", re_variant) while(any(ind <- grepl(pat, x, perl = TRUE))) { y[pos[ind]] <- Map(c, y[pos[ind]], sprintf("Variant=%s", sub(pat, "\\1", x[ind], perl = TRUE))) x[ind] <- sub(pat, "\\2", x[ind], perl = TRUE) ind <- nzchar(x) pos <- pos[ind] x <- x[ind] } if(!length(x)) break ## Extension(s). pat <- sprintf("^-%s(-.*|$)", re_extension) while(any(ind <- grepl(pat, x, perl = TRUE))) { ## ## We keep the singleton prefix: this could be used in ## expansions of registered extensions: currently, ## BCP 47 Extension U ## BCP 47 Extension T y[pos[ind]] <- Map(c, y[pos[ind]], sprintf("Extension=%s", sub(pat, "\\1\\2", x[ind], perl = TRUE))) ## x[ind] <- sub(pat, "\\3", x[ind], perl = TRUE) ind <- nzchar(x) pos <- pos[ind] x <- x[ind] } if(!length(x)) break ## Private use. pat <- sprintf("^-%s(-.*|$)", re_privateuse) if(any(ind <- grepl(pat, x, perl = TRUE))) { y[pos[ind]] <- Map(c, y[pos[ind]], sprintf("Privateuse=%s", substring(sub(pat, "\\1", x[ind], perl = TRUE), 2L))) x[ind] <- sub(pat, "\\4", x[ind], perl = TRUE) } break } } ## Be a nuisance: singletons for extensions must not be duplicated. ind <- as.logical(lapply(y, function(e) { e <- grep("^Extension=", e, value = TRUE) if(!length(e)) return(FALSE) any(duplicated(sub("^Extension=(.).*", "\\1", e))) })) if(any(ind)) bad <- c(bad, which(ind)) if(any(ind <- nzchar(x))) { bad <- c(bad, pos[ind]) } if(length(bad)) { stop("Invalid language tag(s):", paste("\n ", names(y)[bad], collapse = " "), call. = FALSE) } if(!expand) return(y) x <- tolower(unlist(y)) pos <- match(x, IANA_language_subtag_registry$Index) z <- IANA_language_subtag_registry$Description[pos] ## Special case private use ranges. if(!all(lengths(z))) { pos <- match(x, IANA_language_subtag_registry_private_use_index_table) z[pos > 0L | grepl("^privateuse=", x)] <- "Private use" } z <- Map(`names<-`, split(z, rep.int(seq_along(y), lengths(y))), y) names(z) <- names(y) z } get_IANA_language_subtag_registry <- function(con = "https://www.iana.org/assignments/language-subtag-registry") { ## This is a collection of records in tag-value format, but ## unfortunately separated by '%%' lines rather than empty lines, so ## we cannot use read.dcf() directly. Let us keep things simple: ## extract the records, write them out as DCF, and call read.dcf(). lines <- readLines(con) ## The first line is something like ## File-Date: 2009-03-13 ## which we drop for reading the records. fdate <- sub(".*: *", "", lines[1L]) pos <- grep("^%%", lines) lines[c(seq_len(pos[1L]), pos[-1L])] <- "" tcon <- textConnection(lines, encoding = "UTF-8") on.exit(close(tcon)) db <- read.dcf(tcon, all = TRUE) ## Add index for lookups. subtag <- db$Subtag db$Index <- tolower(sprintf("%s=%s", db$Type, ifelse(is.na(subtag), db$Tag, subtag))) db$Type <- factor(db$Type) attr(db, "File_Date") <- fdate db } IANA_language_subtag_registry_language_private_use_subtags <- outer(letters[1L : 20L], letters, function(u, v) sprintf("q%s%s", u, v)) IANA_language_subtag_registry_script_private_use_subtags <- outer(c("a", "b"), letters[1L : 24L], function(u, v) sprintf("Qa%s%s", u, v)) IANA_language_subtag_registry_region_private_use_subtags <- c(sprintf("Q%s", LETTERS[13L : 26L]), sprintf("X%s", LETTERS)) IANA_language_subtag_registry_private_use_index_table <- tolower(c(sprintf("Language=%s", IANA_language_subtag_registry_language_private_use_subtags), sprintf("Script=%s", IANA_language_subtag_registry_script_private_use_subtags), sprintf("Region=%s", IANA_language_subtag_registry_region_private_use_subtags))) NLP/R/wordlist.R0000644000175100001440000000177612521153434013127 0ustar hornikusersWordListDocument <- function(con, encoding = "unknown", meta = list()) { words <- readLines(con, encoding = encoding, warn = FALSE) doc <- list(content = words, meta = meta) class(doc) <- c("WordListDocument", "TextDocument") doc } format.WordListDocument <- function(x, ...) c(.format_TextDocument(x), sprintf("Content: words: %d", length(x$content))) ## print.WordListDocument <- ## function(x, ...) ## { ## writeLines(sprintf("<>", ## length(x$content))) ## invisible(x) ## } content.WordListDocument <- function(x) x$content ## meta.WordListDocument <- ## function(x, tag = NULL, ...) ## if(is.null(tag)) x$meta else x$meta[[tag]] ## `meta<-.WordListDocument` <- ## function(x, tag = NULL, ..., value) ## { ## if(is.null(tag)) ## x$meta <- value ## else ## x$meta[[tag]] <- value ## x ## } as.character.WordListDocument <- words.WordListDocument <- function(x, ...) x$content NLP/R/annotators.R0000644000175100001440000003543313357324620013452 0ustar hornikusers## All annotators should have formals s and a, giving the string to ## annotate and an annotation to start from, and return "their own" ## annotation. Annotator <- function(f, meta = list(), classes = NULL) { if(!identical(names(formals(f)), c("s", "a"))) stop("Annotators must have formals 's' and 'a'.") attr(f, "meta") <- meta class(f) <- .classes_with_default(classes, "Annotator") f } is.Annotator <- function(x) inherits(x, "Annotator") format.Annotator <- function(x, ...) { d <- meta(x, "description") c(sprintf("An annotator inheriting from classes\n %s", paste(class(x), collapse = " ")), if(is.null(d)) { "with no additional description." } else { c("with description", strwrap(d, indent = 2L, exdent = 2L)) }) } ## Annotator generators. ## Provide annotator generators for composite basic NLP tasks (e.g., ## obtaining POS tags for the tokens in all sentences) based on ## functions which perform simple tasks (e.g., obtaining POS tags for ## the token in a single sentence) and return spans/features or simple ## annotations (but do not provide ids themselves). Simple_Para_Token_Annotator <- function(f, meta = list(), classes = NULL) { ## f should be a simple paragraph tokenizer, which takes a string s ## representing the whole text, and returns the spans of the ## paragraphs in s, or a simple annotation with these spans and ## (possibly) additional features. force(f) default <- "Simple_Para_Token_Annotator" classes <- .classes_with_default(classes, default) g <- function(s, a = Annotation()) { s <- as.String(s) y <- f(s) n <- length(y) id <- .seq_id(next_id(a$id), n) type <- rep.int("paragraph", n) if(is.Annotation(y)) { ## Could check whether ids are really missing. y$id <- id y$type <- type # Just making sure ... } else if(is.Span(y)) { y <- as.Annotation(y, id = id, type = type) } else stop("Invalid result from underlying paragraph tokenizer.") y } Annotator(g, meta, classes) } Simple_Sent_Token_Annotator <- function(f, meta = list(), classes = NULL) { ## f should be a simple sentence tokenizer, which takes a string s ## representing the whole text, and returns the spans of the ## sentences in s, or a simple annotation with these spans and ## (possibly) additional features. ## Note that in case paragraph annotations are available, we ## (currently) do not split the whole text into paragraphs before ## performing sentence tokenization. Instead, we add a sentence ## constituents feature for the paragraphs. force(f) default <- "Simple_Sent_Token_Annotator" classes <- .classes_with_default(classes, default) g <- function(s, a = Annotation()) { s <- as.String(s) y <- f(s) n <- length(y) id <- .seq_id(next_id(a$id), n) type <- rep.int("sentence", n) if(is.Annotation(y)) { ## Could check whether ids are really missing. y$id <- id y$type <- type # Just making sure ... } else if(is.Span(y)) { y <- as.Annotation(y, id = id, type = type) } else stop("Invalid result from underlying sentence tokenizer.") if(length(i <- which(a$type == "paragraph"))) { a <- a[i] a$features <- lapply(annotations_in_spans(y, a), function(e) list(constituents = e$id)) y <- c(y, a) } y } Annotator(g, meta, classes) } Simple_Word_Token_Annotator <- function(f, meta = list(), classes = NULL) { ## f should be a simple "word" tokenizer, which takes a string s ## representing a single sentence, and returns the spans of the word ## tokens in s, or a simple annotation with these spans and ## (possibly) additional features. ## The generated annotator adds the sentence offsets and unique ## word token ids, and constituents features for the sentences. force(f) default <- "Simple_Word_Token_Annotator" classes <- .classes_with_default(classes, default) g <- function(s, a) { s <- as.String(s) ## Use the given annotation to extract the sentences. i <- which(a$type == "sentence") if(!length(i)) stop("no sentence token annotations found") ## Obtain the results of the word tokenizer for these sentences. y <- lapply(substring(s, a$start[i], a$end[i]), f) ## Compute ids for the word tokens, and turn results into ## annotations. ## If m is the maximal id used in a and sentence i has n_i ## tokens, then the ids for these start from ## m + 1 + sum(n_j: j < i) ## and have length n_i, of course. if(all(vapply(y, is.Annotation, NA))) { y <- Map(function(u, v) { u$start <- u$start + v u$end <- u$end + v u }, y, a$start[i] - 1L) n <- lengths(y) id <- Map(.seq_id, next_id(a$id) + c(0L, cumsum(head(n, -1L))), n) type <- Map(rep.int, "word", n) y <- Map(function(u, id, type) { u$id <- id u$type <- type # Just making sure ... u }, y, id, type) } else if(all(vapply(y, is.Span, NA))) { y <- Map(`+`, y, a$start[i] - 1L) # Add sentence offsets. n <- lengths(y) id <- Map(.seq_id, next_id(a$id) + c(0L, cumsum(head(n, -1L))), n) type <- Map(rep.int, "word", n) y <- Map(function(u, id, type) as.Annotation(u, id = id, type = type), y, id, type) } else stop("Invalid result from underlying word tokenizer.") ## Constituent features for the sentences. a <- a[i] a$features <- lapply(id, single_feature, "constituents") ## Combine sentence annotation with constituent features and the ## word token annotations. c(a, do.call(c, y)) } Annotator(g, meta, classes) } Simple_POS_Tag_Annotator <- function(f, meta = list(), classes = NULL) { ## f should be a simple POS tagger, which takes a character vector ## giving the word tokens in a sentence, and returns either a ## character vector with the tags, or a list of feature maps with ## the tags as 'POS' feature and possibly other features. ## The generated annotator simply computes an annotation for the ## word tokens with the features obtained from the POS tagger. force(f) default <- "Simple_POS_Tag_Annotator" classes <- .classes_with_default(classes, default) g <- function(s, a) { s <- as.String(s) a <- annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"]) if(!length(a)) stop("no sentence token annotations found") if(!any(lengths(a) > 0L)) stop("no word token annotations found") y <- lapply(s[a], f) if(all(vapply(y, is.character, NA))) features <- lapply(unlist(y), single_feature, "POS") else if(all(vapply(y, is.list, NA))) features <- unlist(y, recursive = FALSE) else stop("Invalid result from underlying POS tagger.") a <- do.call(c, a) a$features <- features ## As simple POS taggers do not return annotations, information ## about the POS tagset cannot be passed as annotation metadata. ## Instead, for now we look for a 'POS_tagset' attribute. ## Similarly for 'POS_tagset_URL'. for(tag in c("POS_tagset", "POS_tagset_URL")) { if(!is.null(val <- attr(f, tag))) attr(a, "meta")[[tag]] <- val } a } Annotator(g, meta, classes) } Simple_Entity_Annotator <- function(f, meta = list(), classes = NULL) { ## f should be a simple entity detector ("named entity recognizer") ## which takes a character vector giving the word tokens in a ## sentence, and return a simple annotation containing the word ## token spans and types of the entities found. ## The generated annotator adds ids and transforms word token spans ## to character spans. force(f) default <- "Simple_Entity_Annotator" classes <- .classes_with_default(classes, default) g <- function(s, a) { s <- as.String(s) i <- next_id(a$id) a <- annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"]) if(!length(a)) stop("no sentence token annotations found") if(!any(lengths(a) > 0L)) stop("no word token annotations found") y <- lapply(a, function(e) { result <- f(s[e]) if(!inherits(result, "Annotation")) stop("Invalid result from underlying name finder.") result$start <- e$start[result$start] result$end <- e$end[result$end] result }) y <- do.call(c, y) y$id <- .seq_id(i, length(y)) y } Annotator(g, meta, classes) } Simple_Chunk_Annotator <- function(f, meta = list(), classes = NULL) { ## f should be a simple chunker, which takes character vectors ## giving the word tokens and the corresponding POS tags as inputs, ## and returns either a character vector with the chunk tags, or a ## list of feature maps with the tags as 'chunk_tag' feature and ## possibly other features. ## The generated annotator simply extracts the word token ## annotations for the sentences, obtains the chunk features for ## these, and returns the word token annotations with these features ## (only). force(f) default <- "Simple_Chunk_Annotator" classes <- .classes_with_default(classes, default) g <- function(s, a) { s <- as.String(s) a <- annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"]) if(!length(a)) stop("no sentence token annotations found") if(!any(lengths(a) > 0L)) stop("no word token annotations found") y <- lapply(a, function(e) f(s[e], .annotation_features_with_template(e, "POS"))) if(all(vapply(y, is.character, NA))) features <- lapply(unlist(y), single_feature, "chunk_tag") else if(all(vapply(y, is.list, NA))) features <- unlist(y, recursive = FALSE) else stop("Invalid result from underlying chunker.") a <- do.call(c, a) a$features <- features a } Annotator(g, meta, classes) } Simple_Stem_Annotator <- function(f, meta = list(), classes = NULL) { ## f should be a simple stemmer, which takes a character vector of ## word tokens and returns the corresponding word stems. ## The generated annotator simply computes an annotation for the ## word tokens with the stem features obtained from the stemmer. force(f) default <- "Simple_Stem_Annotator" classes <- .classes_with_default(classes, default) g <- function(s, a) { s <- as.String(s) a <- a[a$type == "word"] a$features <- lapply(f(s[a]), single_feature, "stem") a } Annotator(g, meta, classes) } sentence_constituents <- function(a) { i <- which(a$type == "sentence") constituents <- lapply(a$features[i], `[[`, "constituents") if(!all(lengths(constituents) > 0L)) { ## Looks like we have an annotation with no constituents ## features for the sentences ... need to compute these. ## Make sure sentences are ordered by character offsets. i <- i[order(a$end[i])] j <- which(a$type == "word") ## Should we also make sure tokens are ordered by character ## offsets? k <- rowSums(outer(a$start[j], a$start[i], ">=")) constituents <- split(a$id[j], k) names(constituents) <- a$id[i][as.integer(names(constituents))] ## Assuming there can not be empty sentences, we could more ## simply do ## names(constituents) <- a$id[i] } else names(constituents) <- a$id[i] constituents } next_id <- function(id) .max_id(id) + 1L single_feature <- function(value, tag) { y <- list(value) names(y) <- tag y } .max_id <- function(id) { id <- id[!is.na(id)] if(!length(id)) 0L else max(id) } .seq_id <- function(f, l) as.integer(seq.int(from = f, length.out = l)) .classes_with_default <- function(classes, default) c(classes[classes != default], default) ## .simple_feature_map <- ## function(x, tag) ## { ## ## Turn a sequence of values x into a list of feature maps with ## ## given tag and respective values in x. ## lapply(x, single_feature, tag) ## } ### * Annotator pipelines Annotator_Pipeline <- function(..., meta = list()) { x <- list(...) if(!all(vapply(x, is.Annotator, FALSE))) stop("all pipeline elements must be annotator objects") .Annotator_Pipeline_from_list_and_meta(x, meta) } ## ## Should we move the is.Annotator checking here, perhaps with a way to ## turn it off? .Annotator_Pipeline_from_list_and_meta <- function(x, meta = list()) { attr(x, "meta") <- meta class(x) <- "Annotator_Pipeline" x } ## as.Annotator_Pipeline <- function(x) UseMethod("as.Annotator_Pipeline") as.Annotator_Pipeline.Annotator_Pipeline <- identity as.Annotator_Pipeline.Annotator <- function(x) .Annotator_Pipeline_from_list_and_meta(list(x)) as.Annotator_Pipeline.list <- function(x) { if(!all(vapply(x, is.Annotator, FALSE))) stop("all pipeline elements must be annotator objects") .Annotator_Pipeline_from_list_and_meta(x) } `[.Annotator_Pipeline` <- function(x, i) .Annotator_Pipeline_from_list_and_meta(unclass(x)[i], meta(x)) as.list.Annotator_Pipeline <- function(x, ...) { x <- unclass(x) attr(x, "meta") <- NULL x } ## No merging of metadata for now. c.Annotator_Pipeline <- function(..., recursive = FALSE) { annotators <- unlist(lapply(list(...), as.Annotator_Pipeline), recursive = FALSE) .Annotator_Pipeline_from_list_and_meta(annotators) } format.Annotator_Pipeline <- function(x, ...) sprintf("An annotator pipeline of length %d.", length(x)) NLP/R/datetime.R0000644000175100001440000000764613036461133013056 0ustar hornikusersISO_8601_datetime_components <- c("year", "mon", "day", "hour", "min", "sec", "tzd") parse_ISO_8601_datetime <- function(x) { x <- as.character(x) n <- length(x) y <- matrix("", n, 7L) dimnames(y) <- list(x, ISO_8601_datetime_components) pos <- seq_along(x) bad <- (is.na(x) | (x == "") | ((nzchar(x) > 10L) && (substring(x, 11L, 11L) != "T"))) if(any(bad)) { pos <- pos[!bad] x <- x[pos] } dates <- substring(x, 1L, 10L) pat <- "^([[:digit:]]{4})(-[[:digit:]]{2})?(-[[:digit:]]{2})?$" m <- regmatches(dates, regexec(pat, dates)) ind <- lengths(m) > 0L if(!all(ind)) { bad[pos[!ind]] <- TRUE pos <- pos[ind] x <- x[ind] m <- m[ind] } y[pos, 1L : 3L] <- do.call(rbind, m)[, 2L : 4L] ind <- (nchar(x) > 10L) if(any(ind)) { if(!all(ind)) { pos <- pos[ind] x <- x[ind] } times <- substring(x, 12L) pat <- paste("^", "([[:digit:]]{2}):([[:digit:]]{2})", "(:[[:digit:]]{2}([.][[:digit:]]+)?)?", "(Z|[+-][[:digit:]]{2}:[[:digit:]]{2})", "$", sep = "") m <- regmatches(times, regexec(pat, times)) ind <- lengths(m) > 0L if(!all(ind)) bad[pos[!ind]] <- TRUE y[pos[ind], 4L : 7L] <- do.call(rbind, m[ind])[, c(2L, 3L, 4L, 6L)] } y[, c(2L, 3L, 6L)] <- substring(y[, c(2L, 3L, 6L)], 2L) ## Warn about the bad entries. if(any(bad)) { warning("Invalid entries:", paste("\n ", rownames(y)[bad], collapse = " ")) y[bad, ] <- "" } ## If we want year to sec as numeric and tzd as character, we need ## to do ## y <- as.data.frame(y, stringsAsFactors = FALSE) ## and convert variables 1 to 6: note that this would turn empty to ## missing ... x <- rownames(y) w <- which(y != "", arr.ind = TRUE) y <- as.data.frame(y, stringsAsFactors = FALSE) y[, 1L : 5L] <- lapply(y[, 1L : 5L], as.integer) y[[6L]] <- as.numeric(y[[6L]]) y <- Map(function(u, v) as.list(u[v]), split(y, seq_len(n)), split(w[, 2L], factor(w[, 1L], seq_len(n)))) names(y) <- x class(y) <- "ISO_8601_datetime" y } `[.ISO_8601_datetime` <- function(x, i) { y <- unclass(x)[i] class(y) <- class(x) y } `$.ISO_8601_datetime` <- function(x, name) { name <- pmatch(name, ISO_8601_datetime_components) as.data.frame(x)[[name]] } as.matrix.ISO_8601_datetime <- function(x, ...) { y <- matrix("", length(x), 7L, dimnames = list(names(x), ISO_8601_datetime_components)) nms <- lapply(x, names) y[cbind(rep.int(seq_along(x), lengths(nms)), match(unlist(nms), ISO_8601_datetime_components))] <- as.character(unlist(x)) y } as.data.frame.ISO_8601_datetime <- function(x, row.names = NULL, optional = FALSE, ...) { y <- as.matrix(x) y[y == ""] <- NA_character_ y <- as.data.frame(y, stringsAsFactors = FALSE) y[, 1L : 5L] <- lapply(y[, 1L : 5L], as.integer) y[[6L]] <- as.numeric(y[[6L]]) y } as.Date.ISO_8601_datetime <- function(x, ...) { y <- as.matrix(x) y[y == ""] <- NA_character_ as.Date(sprintf("%s-%s-%s", y[, 1L], y[, 2L], y[, 3L]), "%Y-%m-%d") } as.POSIXct.ISO_8601_datetime <- function(x, tz = "", ...) as.POSIXct(as.POSIXlt(x)) as.POSIXlt.ISO_8601_datetime <- function(x, tz = "", ...) { y <- as.matrix(x) y[y == ""] <- NA_character_ offsets <- sub(":", "", y[, 7L]) offsets[offsets == "Z"] <- "+0000" y[, 7L] <- offsets strptime(do.call(paste, split(y, col(y))), "%Y %m %d %H %M %OS %z", tz = "UTC") } print.ISO_8601_datetime <- function(x, ...) { y <- as.matrix(x) y <- as.data.frame(y, stringsAsFactors = FALSE) print(y) invisible(x) } NLP/R/spacyr.R0000644000175100001440000000110713337763355012564 0ustar hornikusers## Viewer methods for objects of class "spacyr_parsed" as obtained by ## spacyr::spacy_parse(). words.spacyr_parsed <- function(x, ...) { x$token } sents.spacyr_parsed <- function(x, ...) { split(x$token, x$sentence_id) } tagged_words.spacyr_parsed <- function(x, which = c("pos", "tag"), ...) { which <- match.arg(which) Tagged_Token(x$token, x[[which]]) } tagged_sents.spacyr_parsed <- function(x, which = c("pos", "tag"), ...) { which <- match.arg(which) lapply(split(x, x$sentence_id), function(e) Tagged_Token(e$token, e[[which]])) } NLP/R/annotate.R0000644000175100001440000000053612517716566013102 0ustar hornikusers## annotate() can use a single annotator or an annotator pipeline or ## something coercible to this, such as a list of annotators, and ## recursively calls the given annotators and merges annotations. annotate <- function(s, f, a = Annotation()) { s <- as.String(s) for(e in as.Annotator_Pipeline(f)) a <- merge(a, e(s, a)) a } NLP/R/span.R0000644000175100001440000000654612503505414012220 0ustar hornikusers## A simple span class for storing start and end integer offsets. ## Apache OpenNLP optionally allows storing types in spans: we use ## Annotation objects (with no ids or features) for this. ## Conceptually, a single span is a start/end pair and our Span objects ## are sequences (to allow positional access) of spans, i.e., sequences ## of pairs. ## The implementation actually uses a "pair" (named list of length two) ## of "slots" giving the start and end value sequences. ## Subscripting via [ extracts subsets of spans. ## Subscripting via $ extracts one slot. Span_slot_names <- c("start", "end") Span <- function(start, end) { start <- as.integer(start) end <- as.integer(end) if(length(start) != length(end)) stop("arguments must have the same length") .Span_from_args(start, end) } .Span_from_args <- function(start, end) .Span_from_list(list(start = start, end = end)) .Span_from_list <- function(x) { class(x) <- "Span" x } as.Span <- function(x) UseMethod("as.Span") as.Span.Span <- identity as.Span.Annotation <- function(x) .Span_from_args(x$start, x$end) is.Span <- function(x) inherits(x, "Span") `[.Span` <- function(x, i) .Span_from_list(lapply(unclass(x), `[`, i)) ## ## Implement eventually ... `[<-.Span` <- function(x, i, value) .NotYetImplemented() ## `[[.Span` <- function(x, i) .Span_from_list(lapply(unclass(x), `[[`, i)) ## ## Implement eventually ... `[[<-.Span` <- function(x, i, value) .NotYetImplemented() ## ## $.Span is not really necessary. `$<-.Span` <- function(x, name, value) { n <- length(x) x <- unclass(x) if(is.na(pos <- pmatch(name, Span_slot_names))) stop("invalid element name") value <- as.integer(value) if(length(value) != n) stop("replacement must have the same length as object") x[[pos]] <- value .Span_from_list(x) } Ops.Span <- function(e1, e2) { ## Allow to add offsets. switch(as.character(.Generic), "+" = { if(is.Span(e1) && is.numeric(e2) && (length(e2) == 1L)) return(Span(e1$start + e2, e1$end + e2)) if(is.Span(e2) && is.numeric(e1) && (length(e1) == 1L)) return(Span(e2$start + e1, e2$end + e1)) stop("Invalid operands.") }, stop(gettextf("'%s' not defined for \"Span\" objects", .Generic), domain = NA)) } as.data.frame.Span <- function(x, row.names = NULL, optional = FALSE, ...) { data.frame(start = x$start, end = x$end, row.names = row.names) } as.list.Span <- function(x, ...) lapply(seq_along(x), function(i) x[i]) c.Span <- function(..., recursive = FALSE) { args <- lapply(list(...), function(e) unclass(as.Span(e))) y <- lapply(Span_slot_names, function(e) unlist(lapply(args, `[[`, e))) names(y) <- Span_slot_names .Span_from_list(y) } duplicated.Span <- function(x, incomparables = FALSE, ...) { do.call(`&`, lapply(unclass(x), duplicated)) } format.Span <- function(x, ...) { format(as.data.frame(x), ...) } length.Span <- function(x) length(x$start) names.Span <- function(x) NULL print.Span <- function(x, ...) { print.data.frame(format(x), ..., row.names = FALSE) invisible(x) } unique.Span <- function(x, incomparables = FALSE, ...) x[!duplicated(x)] NLP/R/aptd.R0000644000175100001440000001516413357324561012215 0ustar hornikusersAnnotatedPlainTextDocument <- function(s, a, meta = list()) { s <- as.String(s) ## Be nice. a <- as.Annotation(a) doc <- list(content = s, annotation = a, meta = meta) class(doc) <- c("AnnotatedPlainTextDocument", "PlainTextDocument", "TextDocument") doc } format.AnnotatedPlainTextDocument <- function(x, ...) { c(.format_TextDocument(x), sprintf("Annotations: length: %s", length(x$annotation)), sprintf("Content: chars: %d", nchar(x$content))) } content.AnnotatedPlainTextDocument <- function(x) x$content `content<-.AnnotatedPlainTextDocument` <- function(x, value) stop("content modification is not possible for AnnotatedPlainTextDocument objects") ## meta.AnnotatedPlainTextDocument <- ## function(x, tag = NULL, ...) ## if(is.null(tag)) x$meta else x$meta[[tag]] ## `meta<-.AnnotatedPlainTextDocument` <- ## function(x, tag = NULL, ..., value) ## { ## if(is.null(tag)) ## x$meta <- value ## else ## x$meta[[tag]] <- value ## x ## } as.character.AnnotatedPlainTextDocument <- function(x, ...) x$content annotation <- function(x) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") x$annotation } ## NLTK style functions for high level access words.AnnotatedPlainTextDocument <- function(x, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") s <- x$content a <- x$annotation ## Could check for word token annotations ... s[a[a$type == "word"]] } sents.AnnotatedPlainTextDocument <- function(x, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") s <- x$content a <- x$annotation .sents_from_annotation_and_text(a, s) } .sents_from_annotation_and_text <- function(a, s) { ## Could check for sentence and word token annotations ... s[annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"])] } paras.AnnotatedPlainTextDocument <- function(x, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") s <- x$content a <- x$annotation ## Could check for paragraph annotations ... lapply(annotations_in_spans(a, a[a$type == "paragraph"]), .sents_from_annotation_and_text, s) } tagged_words.AnnotatedPlainTextDocument <- function(x, map = NULL, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") s <- x$content a <- x$annotation ## Could check for word token annotations ... a <- a[a$type == "word"] if(!is.null(map)) a <- .map_POS_tags_Annotation(a, map) .tagged_words_from_annotation_and_text(a, s) } .tagged_words_from_annotation_and_text <- function(a, s) { pos <- .annotation_features_with_template(a, "POS") Tagged_Token(s[a], pos) } tagged_sents.AnnotatedPlainTextDocument <- function(x, map = NULL, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") s <- x$content a <- x$annotation if(!is.null(map)) a <- .map_POS_tags_Annotation(a, map) .tagged_sents_from_annotation_and_text(a, s) } .tagged_sents_from_annotation_and_text <- function(a, s) { ## Could check for word and sentence token annotations ... lapply(annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"]), .tagged_words_from_annotation_and_text, s) } tagged_paras.AnnotatedPlainTextDocument <- function(x, map = NULL, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") s <- x$content a <- x$annotation if(!is.null(map)) a <- .map_POS_tags_Annotation(a, map) ## Could check for paragraph annotations ... lapply(annotations_in_spans(a, a[a$type == "paragraph"]), .tagged_sents_from_annotation_and_text, s) } parsed_sents.AnnotatedPlainTextDocument <- function(x, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") a <- x$annotation .parsed_sents_from_annotation(a) } .parsed_sents_from_annotation <- function(a) { ## Could check for sentence token annotations ... a <- a[a$type == "sentence"] ptexts <- .annotation_features_with_template(a, "parse") lapply(ptexts, Tree_parse) } parsed_paras.AnnotatedPlainTextDocument <- function(x, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") a <- x$annotation ## Could check for paragraph annotations ... lapply(annotations_in_spans(a, a[a$type == "paragraph"]), .parsed_sents_from_annotation) } chunked_sents.AnnotatedPlainTextDocument <- function(x, ...) { if(!inherits(x, "AnnotatedPlainTextDocument")) stop("argument 'x' must be an AnnotatedPlainTextDocument object") s <- x$content a <- x$annotation ## Require annotations with POS and chunk_tag features, as obtained ## e.g. with the Apache OpenNLP POS tag and chunk annotators. We ## could alternatively use annotations with parse features and ## flatten the parse trees. ## Could check for word and sentence token annotations ... lapply(annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"]), function(a) { ## Could check for POS and chunk tag features ... ptags <- .annotation_features_with_template(a, "POS") ctags <- .annotation_features_with_template(a, "chunk_tag") words <- s[a] chunk_tree_from_chunk_info(words, ptags, ctags) }) } .map_POS_tags_Annotation <- function(x, map) { map <- POS_tag_mapper(map, meta(x, "POS_tagset")) x$features <- lapply(x$features, function(e) { if(!is.null(pos <- e$POS)) e$POS <- map(pos) e }) x } .annotation_features_with_template <- function(x, tag, FUN.VALUE = "") { tryCatch(vapply(x$features, function(e) e[[tag]], FUN.VALUE), error = function(e) { stop(sprintf("incomplete or invalid '%s' features", tag), call. = FALSE) }) } NLP/R/tree.R0000644000175100001440000000671712517657432012233 0ustar hornikusersTree <- function(value, children = list()) { y <- list(value = value, children = as.list(children)) class(y) <- "Tree" y } format.Tree <- function(x, width = 0.9 * getOption("width"), indent = 0, brackets = c("(", ")"), ...) { ffmt <- function(x) { sprintf("%s%s %s%s", brackets[1L], x$value, paste(sapply(x$children, function(e) { if(inherits(e, "Tree")) ffmt(e) else format(e) }), collapse = " "), brackets[2L]) } s <- ffmt(x) if(nchar(s) + indent < width) return(s) y <- sapply(x$children, function(e) { if(inherits(e, "Tree")) format(e, width = width, indent = indent + 2L, brackets = brackets) else format(e) }) y <- sprintf("\n%s%s", paste(rep.int(" ", indent + 2L), collapse = ""), y) sprintf("%s%s%s%s", brackets[1L], x$value, paste(y, collapse = ""), brackets[2L]) } ## print.Tree <- ## function(x, ...) ## { ## writeLines(format(x, ...)) ## invisible(x) ## } Tree_parse <- function(x, brackets = c("(", ")")) { errfmt <- function(token, expected) { sprintf("expected %s but got %s", expected, token) } re_o <- sprintf("\\%s", brackets[1L]) # open re_c <- sprintf("\\%s", brackets[2L]) # close re_n <- sprintf("[^\\s%s%s]+", re_o, re_c) # node re_l <- sprintf("[^\\s%s%s]+", re_o, re_c) # leaf re <- sprintf("%s\\s*(%s)?|%s|(%s)", re_o, re_n, re_c, re_l) m <- gregexpr(re, x, perl = TRUE) stack <- list(list(NULL, list())) for(token in regmatches(x, m)[[1L]]) { if(substring(token, 1L, 1L) == "(") { if((length(stack) == 1L) && (length(stack[[1L]][[2L]]) > 0L)) stop(errfmt(sQuote(token), "end of string")) value <- sub("\\s*", "", substring(token, 2L)) stack <- c(stack, list(Tree(value, list()))) } else if(token == ")") { if((n <- length(stack)) == 1L) { if(!length(stack[[1L]][[2L]])) stop(errfmt(sQuote(token), sQuote(brackets[1L]))) else stop(errfmt(sQuote(token), "end of string")) } elt <- stack[[n]] ## class(elt) <- "Tree" stack <- stack[-n] n <- n - 1L stack[[n]][[2L]] <- c(stack[[n]][[2L]], list(elt)) } else { if((n <- length(stack)) == 1L) stop(errfmt(sQuote(token), sQuote(brackets[1L]))) stack[[n]][[2L]] <- c(stack[[n]][[2L]], list(token)) } } if(length(stack) > 1L) stop(errfmt("end of string", sQuote(brackets[2L]))) else if(!length(stack[[1L]][[2L]])) stop(errfmt("end of string", sQuote(brackets[1L]))) stack[[1L]][[2L]][[1L]] } Tree_apply <- function(x, f, recursive = FALSE) { if(!recursive) return(lapply(x$children, f)) g <- function(e) { y <- f(e) if(inherits(e, "Tree")) list(y, lapply(e$children, g)) else y } lapply(x$children, g) } NLP/R/ngram.R0000644000175100001440000000061012474110665012354 0ustar hornikusersngrams <- function(x, n) { N <- length(x) n <- n[(n >= 1L) & (n <= N)] lapply(unlist(lapply(n, function(k) { pos <- seq_len(k) lapply(seq.int(0, N - k), `+`, pos) }), recursive = FALSE), function(e) x[e]) } NLP/MD50000644000175100001440000000510413362126615011236 0ustar hornikusers6ad666dbdf07d0c71c5da17250225767 *DESCRIPTION cbb32c652ba457c6cfcb6e4221edb83a *NAMESPACE 68230f5b697cb282615c5f24544fb720 *R/annotate.R b32662f311cc8a7e9713cc7df81c2a99 *R/annotation.R 0ff4e30b9fb2b2c698fd99c16ad5f842 *R/annotators.R 06a8f0e3b35d1087146c0070ca6c4f3c *R/aptd.R aabe60a80660c2916373e429baf65436 *R/cleannlp.R 4d137191ce73c09e783ce10354878782 *R/conll.R ea6bedd7b78dde569080a2b402f29e31 *R/conllu.R 1eea4d7d7b2b1eeea74a78091819eaa5 *R/datetime.R 8719adb9925c8f93aab0b0d86c3dcfe6 *R/generics.R 440039df75036e35ffc94f131f043e26 *R/language.R 8379bdef18713b0ecb99b8ac396450a0 *R/ngram.R c6495d9526f33fda1de5b5e3d7279561 *R/spacyr.R 58bcbd30d5d9a8e395a4fda8d478a767 *R/span.R 35d690b3ed8f2afe80711a6d651678a2 *R/string.R 9858170f3b1d82da8f44bf614c361796 *R/sysdata.rda 5de59c9b5892f7d8d02528145c59204a *R/tnt.R 765811bd3df5707c9cb346bcc90e03a5 *R/tokenize.R ff6b88b533ee9947d9678898b585b4e1 *R/tree.R 4b2706888e9753775a53ff49a970e36f *R/ttd.R b311a3b5d8975bf6668c2d291285e85c *R/udpipe.R 6af7bebbf00ecd79f85c99187bc7cefa *R/utils.R b21c0cbc0cc217d035071f33dfeac9da *R/viewers.R c1f351e3ab36cc882b6ae7626f423533 *R/wordlist.R c5b17a0d86d6a55cd79435ecdcb2250b *inst/po/en@quot/LC_MESSAGES/R-NLP.mo 708dff54d1cbd38c26083b534ceec207 *inst/texts/stanford.rds c99abe064b5f0da0ef4966740aa13431 *man/AnnotatedPlainTextDocument.Rd 53f4422eefea39e1d9d23639393ccae6 *man/Annotation.Rd 6e4f79c7f155ed43628104851db52cb5 *man/Annotator.Rd 4a5fbf59255f40b1893e5306f869447d *man/CoNLLTextDocument.Rd 9d76f463b03ee003ca03b5e08f95d488 *man/CoNLLUTextDocument.Rd f153bffba3e2259288df2f51564e91c1 *man/Span.Rd 97a707a3526f6a0f2166a2c5f56bf6de *man/String.Rd 5307d801652f793c18187d0672b15dcb *man/TaggedTextDocument.Rd 82a5eb65b8fff6ecb1bda2818873dec5 *man/Tagged_Token.Rd bd0514ec3a9f5f18a422c7e5e7113a05 *man/TextDocument.Rd 424e17206654615bf8686fe16939f363 *man/Tokenizer.Rd 6df09248be4dc1fa24c4b3c3693e5f20 *man/Tree.Rd 87f52a9560fccb3f7d8591d2f90939b0 *man/WordListDocument.Rd 029f8becf569972e5809e7e5917f7314 *man/annotate.Rd cd795f9471a96beac4c836b1d6ea7d19 *man/annotations_in_spans.Rd 4f1067404a36f11ac97cbb38f9e4acde *man/annotators.Rd 5c3f85fbed985be1eba2a91efb1ac76e *man/datetime.Rd 95ba0807805196d2a5873fedd179ba67 *man/features.Rd b95f45ebfcda3d640a3045daf4bff61a *man/generics.Rd e81356f1c15ef0735cb52a6df4a227a4 *man/language.Rd 1c83d8d4b6d39bd74ce34c8c5f7f3516 *man/ngrams.Rd 91db31dec9384e32e1aeb77068e753c5 *man/tagsets.Rd cde03cad007456c9cbc598543e16e12b *man/tokenizers.Rd 02e1fc6afdcc13025e034272636e061d *man/utils.Rd 8e60531d555aca515ee2c291ad588c94 *man/viewers.Rd 4d1dfef1a602b0b2cd87100a04c1da7e *po/R-NLP.pot NLP/DESCRIPTION0000644000175100001440000000120713362126615012434 0ustar hornikusersPackage: NLP Version: 0.2-0 Title: Natural Language Processing Infrastructure Authors@R: person("Kurt", "Hornik", role = c("aut", "cre"), email = "Kurt.Hornik@R-project.org", comment = c(ORCID = "0000-0003-4198-9911")) Description: Basic classes and methods for Natural Language Processing. License: GPL-3 Imports: utils Depends: R (>= 3.2.0) Enhances: udpipe, spacyr, cleanNLP NeedsCompilation: no Packaged: 2018-10-18 15:27:32 UTC; hornik Author: Kurt Hornik [aut, cre] () Maintainer: Kurt Hornik Repository: CRAN Date/Publication: 2018-10-18 15:58:05 UTC NLP/man/0000755000175100001440000000000013362123135011473 5ustar hornikusersNLP/man/CoNLLUTextDocument.Rd0000644000175100001440000000623613333070332015367 0ustar hornikusers\name{CoNLLUTextDocument} \alias{CoNLLUTextDocument} \title{ CoNNL-U Text Documents } \description{ Create text documents from CoNNL-U format files. } \usage{ CoNLLUTextDocument(con, meta = list()) } \arguments{ \item{con}{a connection object or a character string. See \code{\link{scan}()} for details. } \item{meta}{a named or empty list of document metadata tag-value pairs.} } \details{ The CoNLL-U format (see \url{http://universaldependencies.org/format.html}) is a CoNLL-style format for annotated texts popularized and employed by the Universal Dependencies project (see \url{http://universaldependencies.org/}). For each \dQuote{word} in the text, this provides exactly the 10 fields \code{ID}, \code{FORM} (word form or punctuation symbol), \code{LEMMA} (lemma or stem of word form), \code{UPOSTAG} (universal part-of-speech tag, see \url{http://universaldependencies.org/u/pos/index.html}), \code{XPOSTAG} (language-specific part-of-speech tag, may be unavailable), \code{FEATS} (list of morphological features), \code{HEAD}, \code{DEPREL}, \code{DEPS}, and \code{MISC}. The lines with these fields and optional comments are read from the given connection and split into fields using \code{\link{scan}()}. This is combined with consecutive sentence ids into a data frame used for representing the annotation information, and together with the given metadata returned as a CoNLL-U text document inheriting from classes \code{"CoNLLUTextDocument"} and \code{"\link{TextDocument}"}. The complete annotation information data frame can be extracted via \code{content()}. CoNLL-U v2 requires providing the complete texts of each sentence (or a reconstruction thereof) in \samp{# text =} comment lines. Where consistently provided, these are made avaialable in the \code{text} attribute of the content data frame. In addition, there are methods for generics \code{\link{as.character}()}, \code{\link{words}()}, \code{\link{sents}()}, \code{\link{tagged_words}()}, and \code{\link{tagged_sents}()} and class \code{"CoNLLUTextDocument"}, which should be used to access the text in such text document objects. The CoNLL-U format allows to represent both words and (multiword) tokens (see section \sQuote{Words, Tokens and Empty Nodes} in the format documentation), as distinguished by ids being integers or integer ranges, with the words being annotated further. One can use \code{as.character()} to extract the \emph{tokens}; all other viewers listed above use the \emph{words}. Finally, the viewers incorporating POS tags take a \code{which} argument to specify using the univeral or language-specific tags, by giving a substring of \code{"UPOSTAG"} (default) or \code{"XPOSTAG"}. } \value{ An object inheriting from \code{"CoNLLUTextDocument"} and \code{"\link{TextDocument}"}. } \seealso{ \code{\link{TextDocument}} for basic information on the text document infrastructure employed by package \pkg{NLP}. \url{http://universaldependencies.org/} for access to the Universal Dependencies treebanks, which provide annotated texts in \emph{many} different languages using CoNLL-U format. } NLP/man/annotate.Rd0000644000175100001440000000442313333064776013613 0ustar hornikusers\name{annotate} \alias{annotate} \title{Annotate text strings} \description{ Compute annotations by iteratively calling the given annotators with the given text and current annotations, and merging the newly computed annotations with the current ones. } \usage{ annotate(s, f, a = Annotation()) } \arguments{ \item{s}{a \code{\link{String}} object, or something coercible to this using \code{\link{as.String}} (e.g., a character string with appropriate encoding information).} \item{f}{an \code{\link{Annotator}} or \code{\link{Annotator_Pipeline}} object, or something coercible to the latter via \code{\link{as.Annotator_Pipeline}()} (such as a list of annotator objects).} \item{a}{an \code{\link{Annotation}} object giving the annotations to start with.} } \value{ An \code{\link{Annotation}} object containing the iteratively computed and merged annotations. } \examples{ ## A simple text. s <- String(" First sentence. Second sentence. ") ## ****5****0****5****0****5****0****5** ## A very trivial sentence tokenizer. sent_tokenizer <- function(s) { s <- as.String(s) m <- gregexpr("[^[:space:]][^.]*\\\\.", s)[[1L]] Span(m, m + attr(m, "match.length") - 1L) } ## (Could also use Regexp_Tokenizer() with the above regexp pattern.) ## A simple sentence token annotator based on the sentence tokenizer. sent_token_annotator <- Simple_Sent_Token_Annotator(sent_tokenizer) ## Annotate sentence tokens. a1 <- annotate(s, sent_token_annotator) a1 ## A very trivial word tokenizer. word_tokenizer <- function(s) { s <- as.String(s) ## Remove the last character (should be a period when using ## sentences determined with the trivial sentence tokenizer). s <- substring(s, 1L, nchar(s) - 1L) ## Split on whitespace separators. m <- gregexpr("[^[:space:]]+", s)[[1L]] Span(m, m + attr(m, "match.length") - 1L) } ## A simple word token annotator based on the word tokenizer. word_token_annotator <- Simple_Word_Token_Annotator(word_tokenizer) ## Annotate word tokens using the already available sentence token ## annotations. a2 <- annotate(s, word_token_annotator, a1) a2 ## Can also perform sentence and word token annotations in a pipeline: p <- Annotator_Pipeline(sent_token_annotator, word_token_annotator) annotate(s, p) } NLP/man/annotators.Rd0000644000175100001440000002111312520713754014157 0ustar hornikusers\name{annotators} \alias{Simple_Para_Token_Annotator} \alias{Simple_Sent_Token_Annotator} \alias{Simple_Word_Token_Annotator} \alias{Simple_POS_Tag_Annotator} \alias{Simple_Entity_Annotator} \alias{Simple_Chunk_Annotator} \alias{Simple_Stem_Annotator} \alias{Simple annotator generators} \title{Simple annotator generators} \description{ Create annotator objects for composite basic NLP tasks based on functions performing simple basic tasks. } \usage{ Simple_Para_Token_Annotator(f, meta = list(), classes = NULL) Simple_Sent_Token_Annotator(f, meta = list(), classes = NULL) Simple_Word_Token_Annotator(f, meta = list(), classes = NULL) Simple_POS_Tag_Annotator(f, meta = list(), classes = NULL) Simple_Entity_Annotator(f, meta = list(), classes = NULL) Simple_Chunk_Annotator(f, meta = list(), classes = NULL) Simple_Stem_Annotator(f, meta = list(), classes = NULL) } \arguments{ \item{f}{a function performing a \dQuote{simple} basic NLP task (see \bold{Details}).} \item{meta}{an empty or named list of annotator (pipeline) metadata tag-value pairs.} \item{classes}{a character vector or \code{NULL} (default) giving classes to be used for the created annotator object in addition to the default ones (see \bold{Details}).} } \details{ The purpose of these functions is to facilitate the creation of annotators for basic NLP tasks as described below. \code{Simple_Para_Token_Annotator()} creates \dQuote{simple} paragraph token annotators. Argument \code{f} should be a paragraph tokenizer, which takes a string \code{s} with the whole text to be processed, and returns the spans of the paragraphs in \code{s}, or an annotation object with these spans and (possibly) additional features. The generated annotator inherits from the default classes \code{"Simple_Para_Token_Annotator"} and \code{"Annotator"}. It uses the results of the simple paragraph tokenizer to create and return annotations with unique ids and type \sQuote{paragraph}. \code{Simple_Sent_Token_Annotator()} creates \dQuote{simple} sentence token annotators. Argument \code{f} should be a sentence tokenizer, which takes a string \code{s} with the whole text to be processed, and returns the spans of the sentences in \code{s}, or an annotation object with these spans and (possibly) additional features. The generated annotator inherits from the default classes \code{"Simple_Sent_Token_Annotator"} and \code{"Annotator"}. It uses the results of the simple sentence tokenizer to create and return annotations with unique ids and type \sQuote{sentence}, possibly combined with sentence constituent features for already available paragraph annotations. \code{Simple_Word_Token_Annotator()} creates \dQuote{simple} word token annotators. Argument \code{f} should be a simple word tokenizer, which takes a string \code{s} giving a sentence to be processed, and returns the spans of the word tokens in \code{s}, or an annotation object with these spans and (possibly) additional features. The generated annotator inherits from the default classes \code{"Simple_Word_Token_Annotator"} and \code{"Annotator"}. It uses already available sentence token annotations to extract the sentences and obtains the results of the word tokenizer for these. It then adds the sentence character offsets and unique word token ids, and word token constituents features for the sentences, and returns the word token annotations combined with the augmented sentence token annotations. \code{Simple_POS_Tag_Annotator()} creates \dQuote{simple} POS tag annotators. Argument \code{f} should be a simple POS tagger, which takes a character vector giving the word tokens in a sentence, and returns either a character vector with the tags, or a list of feature maps with the tags as \sQuote{POS} feature and possibly other features. The generated annotator inherits from the default classes \code{"Simple_POS_Tag_Annotator"} and \code{"Annotator"}. It uses already available sentence and word token annotations to extract the word tokens for each sentence and obtains the results of the simple POS tagger for these, and returns annotations for the word tokens with the features obtained from the POS tagger. \code{Simple_Entity_Annotator()} creates \dQuote{simple} entity annotators. Argument \code{f} should be a simple entity detector (\dQuote{named entity recognizer}) which takes a character vector giving the word tokens in a sentence, and return an annotation object with the \emph{word} token spans, a \sQuote{kind} feature giving the kind of the entity detected, and possibly other features. The generated annotator inherits from the default classes \code{"Simple_Entity_Annotator"} and \code{"Annotator"}. It uses already available sentence and word token annotations to extract the word tokens for each sentence and obtains the results of the simple entity detector for these, transforms word token spans to character spans and adds unique ids, and returns the combined entity annotations. \code{Simple_Chunk_Annotator()} creates \dQuote{simple} chunk annotators. Argument \code{f} should be a simple chunker, which takes as arguments character vectors giving the word tokens and the corresponding POS tags, and returns either a character vector with the chunk tags, or a list of feature lists with the tags as \sQuote{chunk_tag} feature and possibly other features. The generated annotator inherits from the default classes \code{"Simple_Chunk_Annotator"} and \code{"Annotator"}. It uses already available annotations to extract the word tokens and POS tags for each sentence and obtains the results of the simple chunker for these, and returns word token annotations with the chunk features (only). \code{Simple_Stem_Annotator()} creates \dQuote{simple} stem annotators. Argument \code{f} should be a simple stemmer, which takes as arguments a character vector giving the word tokens, and returns a character vector with the corresponding word stems. The generated annotator inherits from the default classes \code{"Simple_Stem_Annotator"} and \code{"Annotator"}. It uses already available annotations to extract the word tokens, and returns word token annotations with the corresponding stem features (only). In all cases, if the underlying simple processing function returns annotation objects these should not provide their own ids (or use such in the features), as the generated annotators will necessarily provide these (the already available annotations are only available at the annotator level, but not at the simple processing level). } \value{ An annotator object inheriting from the given classes and the default ones. } \seealso{ Package \pkg{openNLP} which provides annotator generators for sentence and word tokens, POS tags, entities and chunks, using processing functions based on the respective Apache OpenNLP MaxEnt processing resources. } \examples{ ## A simple text. s <- String(" First sentence. Second sentence. ") ## ****5****0****5****0****5****0****5** ## A very trivial sentence tokenizer. sent_tokenizer <- function(s) { s <- as.String(s) m <- gregexpr("[^[:space:]][^.]*\\\\.", s)[[1L]] Span(m, m + attr(m, "match.length") - 1L) } ## (Could also use Regexp_Tokenizer() with the above regexp pattern.) sent_tokenizer(s) ## A simple sentence token annotator based on the sentence tokenizer. sent_token_annotator <- Simple_Sent_Token_Annotator(sent_tokenizer) sent_token_annotator a1 <- annotate(s, sent_token_annotator) a1 ## Extract the sentence tokens. s[a1] ## A very trivial word tokenizer. word_tokenizer <- function(s) { s <- as.String(s) ## Remove the last character (should be a period when using ## sentences determined with the trivial sentence tokenizer). s <- substring(s, 1L, nchar(s) - 1L) ## Split on whitespace separators. m <- gregexpr("[^[:space:]]+", s)[[1L]] Span(m, m + attr(m, "match.length") - 1L) } lapply(s[a1], word_tokenizer) ## A simple word token annotator based on the word tokenizer. word_token_annotator <- Simple_Word_Token_Annotator(word_tokenizer) word_token_annotator a2 <- annotate(s, word_token_annotator, a1) a2 ## Extract the word tokens. s[subset(a2, type == "word")] ## A simple word token annotator based on wordpunct_tokenizer(): word_token_annotator <- Simple_Word_Token_Annotator(wordpunct_tokenizer, list(description = "Based on wordpunct_tokenizer().")) word_token_annotator a2 <- annotate(s, word_token_annotator, a1) a2 ## Extract the word tokens. s[subset(a2, type == "word")] } NLP/man/tokenizers.Rd0000644000175100001440000000415113333064645014170 0ustar hornikusers\name{tokenizers} \alias{Regexp_Tokenizer} \alias{blankline_tokenizer} \alias{whitespace_tokenizer} \alias{wordpunct_tokenizer} \title{Regexp tokenizers} \description{ Tokenizers using regular expressions to match either tokens or separators between tokens. } \usage{ Regexp_Tokenizer(pattern, invert = FALSE, ..., meta = list()) blankline_tokenizer(s) whitespace_tokenizer(s) wordpunct_tokenizer(s) } \arguments{ \item{pattern}{a character string giving the regular expression to use for matching.} \item{invert}{a logical indicating whether to match separators between tokens.} \item{...}{further arguments to be passed to \code{\link{gregexpr}()}.} \item{meta}{a named or empty list of tokenizer metadata tag-value pairs.} \item{s}{a \code{\link{String}} object, or something coercible to this using \code{\link{as.String}()} (e.g., a character string with appropriate encoding information).} } \details{ \code{Regexp_Tokenizer()} creates regexp span tokenizers which use the given \code{pattern} and \code{...} arguments to match tokens or separators between tokens via \code{\link{gregexpr}()}, and then transform the results of this into character spans of the tokens found. \code{whitespace_tokenizer()} tokenizes by treating any sequence of whitespace characters as a separator. \code{blankline_tokenizer()} tokenizes by treating any sequence of blank lines as a separator. \code{wordpunct_tokenizer()} tokenizes by matching sequences of alphabetic characters and sequences of (non-whitespace) non-alphabetic characters. } \value{ \code{Regexp_Tokenizer()} returns the created regexp span tokenizer. \code{blankline_tokenizer()}, \code{whitespace_tokenizer()} and \code{wordpunct_tokenizer()} return the spans of the tokens found in \code{s}. } \seealso{ \code{\link{Span_Tokenizer}()} for general information on span tokenizer objects. } \examples{ ## A simple text. s <- String(" First sentence. Second sentence. ") ## ****5****0****5****0****5****0****5** spans <- whitespace_tokenizer(s) spans s[spans] spans <- wordpunct_tokenizer(s) spans s[spans] } NLP/man/features.Rd0000644000175100001440000000310713362122624013603 0ustar hornikusers\name{features} \alias{features} \title{Extract Annotation Features} \description{ Conveniently extract features from annotations and annotated plain text documents. } \usage{ features(x, type = NULL, simplify = TRUE) } \arguments{ \item{x}{an object inheriting from class \code{"Annotation"} or \code{"AnnotatedPlainTextDocument"}.} \item{type}{a character vector of annotation types to be used for selecting annotations, or \code{NULL} (default) to use all annotations. When selecting, the elements of \code{type} will partially be matched against the annotation types.} \item{simplify}{a logical indicating whether to simplify feature values to a vector.} } \details{ \code{features()} conveniently gathers all feature tag-value pairs in the selected annotations into a data frame with variables the values for all tags found (using a \code{NULL} value for tags without a value). In general, variables will be \emph{lists} of extracted values. By default, variables where all elements are length one atomic vectors are simplified into an atomic vector of values. The values for specific tags can be extracted by suitably subscripting the obtained data frame. } \examples{ ## Use a pre-built annotated plain text document, ## see ? AnnotatedPlainTextDocument. doc <- readRDS(system.file("texts", "stanford.rds", package = "NLP")) ## Extract features of all *word* annotations in doc: x <- features(doc, "word") ## Could also have abbreviated "word" to "w". x ## Only lemmas: x$lemma ## Words together with lemmas: paste(words(doc), x$lemma, sep = "/") } NLP/man/WordListDocument.Rd0000644000175100001440000000233613333071074015236 0ustar hornikusers\name{WordListDocument} \alias{WordListDocument} \title{Word List Text Documents} \description{ Create text documents from word lists. } \usage{ WordListDocument(con, encoding = "unknown", meta = list()) } \arguments{ \item{con}{a connection object or a character string. See \code{\link{readLines}()} for details. } \item{encoding}{encoding to be assumed for input strings. See \code{\link{readLines}()} for details. } \item{meta}{a named or empty list of document metadata tag-value pairs.} } \details{ \code{WordListDocument()} uses \code{\link{readLines}()} to read collections of words from connections for which each line provides one word, with blank lines ignored, and returns a word list document object which inherits from classes \code{"WordListDocument"} and \code{"\link{TextDocument}"}. The methods for generics \code{\link{words}()} and \code{\link{as.character}()} and class \code{"WordListDocument"} can be used to extract the words. } \value{ A word list document object inheriting from \code{"WordListDocument"} and \code{"\link{TextDocument}"}. } \seealso{ \code{\link{TextDocument}} for basic information on the text document infrastructure employed by package \pkg{NLP}. } NLP/man/Tree.Rd0000644000175100001440000000635513333066310012671 0ustar hornikusers\name{Tree} \alias{Tree} \alias{format.Tree} \alias{print.Tree} \alias{Tree_parse} \alias{Tree_apply} \title{Tree objects} \description{Creation and manipulation of tree objects.} \usage{ Tree(value, children = list()) \method{format}{Tree}(x, width = 0.9 * getOption("width"), indent = 0, brackets = c("(", ")"), ...) Tree_parse(x, brackets = c("(", ")")) Tree_apply(x, f, recursive = FALSE) } \arguments{ \item{value}{a (non-tree) node value of the tree.} \item{children}{a list giving the children of the tree.} \item{x}{a tree object for the \code{format()} method and \code{Tree_apply()}; a character string for \code{Tree_parse()}.} \item{width}{a positive integer giving the target column for a single-line nested bracketting.} \item{indent}{a non-negative integer giving the indentation used for formatting.} \item{brackets}{a character vector of length two giving the pair of opening and closing brackets to be employed for formatting or parsing.} \item{...}{further arguments passed to or from other methods.} \item{f}{a function to be applied to the children nodes.} \item{recursive}{a logical indicating whether to apply \code{f} recursively to the children of the children and so forth.} } \details{ Trees give hierarchical groupings of leaves and subtrees, starting from the root node of the tree. In natural language processing, the syntactic structure of sentences is typically represented by parse trees (e.g., \url{https://en.wikipedia.org/wiki/Concrete_syntax_tree}) and displayed using nested brackettings. The tree objects in package \pkg{NLP} are patterned after the ones in NLTK (\url{http://nltk.org}), and primarily designed for representing parse trees. A tree object consists of the value of the root node and its children as a list of leaves and subtrees, where the leaves are elements with arbitrary non-tree values (and not subtrees with no children). The value and children can be extracted via \code{$} subscripting using names \code{value} and \code{children}, respectively. There is a \code{format()} method for tree objects: this first tries a nested bracketting in a single line of the given width, and if this is not possible, produces a nested indented bracketting. The \code{print()} method uses the \code{format()} method, and hence its arguments to control the formatting. \code{Tree_parse()} reads nested brackettings into a tree object. } \examples{ x <- Tree(1, list(2, Tree(3, list(4)), 5)) format(x) x$value x$children p <- Tree("VP", list(Tree("V", list("saw")), Tree("NP", list("him")))) p <- Tree("S", list(Tree("NP", list("I")), p)) p ## Force nested indented bracketting: print(p, width = 10) s <- "(S (NP I) (VP (V saw) (NP him)))" p <- Tree_parse(s) p ## Extract the leaves by recursively traversing the children and ## recording the non-tree ones: Tree_leaf_gatherer <- function() { v <- list() list(update = function(e) if(!inherits(e, "Tree")) v <<- c(v, list(e)), value = function() v, reset = function() { v <<- list() }) } g <- Tree_leaf_gatherer() y <- Tree_apply(p, g$update, recursive = TRUE) g$value() } NLP/man/AnnotatedPlainTextDocument.Rd0000644000175100001440000000676013336501160017237 0ustar hornikusers\name{AnnotatedPlainTextDocument} \alias{AnnotatedPlainTextDocument} \alias{annotation} \title{Annotated Plain Text Documents} \description{ Create annotated plain text documents from plain text and collections of annotations for this text. } \usage{ AnnotatedPlainTextDocument(s, a, meta = list()) annotation(x) } \arguments{ \item{s}{a \code{\link{String}} object, or something coercible to this using \code{\link{as.String}()} (e.g., a character string with appropriate encoding information).} \item{a}{an \code{\link{Annotation}} object with annotations for \code{x}.} \item{meta}{a named or empty list of document metadata tag-value pairs.} \item{x}{an object inheriting from class \code{"AnnotatedPlainTextDocument"}.} } \details{ Annotated plain text documents combine plain text with annotations for the text. A typical workflow is to use \code{\link{annotate}()} with suitable annotator pipelines to obtain the annotations, and then use \code{AnnotatedPlainTextDocument()} to combine these with the text being annotated. This yields an object inheriting from \code{"AnnotatedPlainTextDocument"} and \code{"\link{TextDocument}"}, from which the text and annotations can be obtained using, respectively, \code{\link{as.character}()} and \code{annotation()}. There are methods for class \code{"AnnotatedPlainTextDocument"} and generics \code{\link{words}()}, \code{\link{sents}()}, \code{\link{paras}()}, \code{\link{tagged_words}()}, \code{\link{tagged_sents}()}, \code{\link{tagged_paras}()}, \code{\link{chunked_sents}()}, \code{\link{parsed_sents}()} and \code{\link{parsed_paras}()} providing structured views of the text in such documents. These all require the necessary annotations to be available in the annotation object used. The methods for generics \code{\link{tagged_words}()}, \code{\link{tagged_sents}()} and \code{\link{tagged_paras}()} provide a mechanism for mapping POS tags via the \code{map} argument, see section \bold{Details} in the help page for \code{\link{tagged_words}()} for more information. The POS tagset used will be inferred from the \code{POS_tagset} metadata element of the annotation object used. } \value{ For \code{AnnotatedPlainTextDocument()}, an annotated plain text document object inheriting from \code{"AnnotatedPlainTextTextDocument"} and \code{"\link{TextDocument}"}. For \code{annotation()}, an \code{\link{Annotation}} object. } \seealso{ \code{\link{TextDocument}} for basic information on the text document infrastructure employed by package \pkg{NLP}. } \examples{ ## Use a pre-built annotated plain text document obtained by employing an ## annotator pipeline from package 'StanfordCoreNLP', available from the ## repository at , using the following code: ## require("StanfordCoreNLP") ## s <- paste("Stanford University is located in California.", ## "It is a great university.") ## p <- StanfordCoreNLP_Pipeline(c("pos", "lemma", "parse")) ## doc <- AnnotatedPlainTextDocument(s, p(s)) doc <- readRDS(system.file("texts", "stanford.rds", package = "NLP")) doc ## Extract available annotation: a <- annotation(doc) a ## Structured views: sents(doc) tagged_sents(doc) tagged_sents(doc, map = Universal_POS_tags_map) parsed_sents(doc) ## Add (trivial) paragraph annotation: s <- as.character(doc) a <- annotate(s, Simple_Para_Token_Annotator(blankline_tokenizer), a) doc <- AnnotatedPlainTextDocument(s, a) ## Structured view: paras(doc) } NLP/man/annotations_in_spans.Rd0000644000175100001440000000214213333064566016222 0ustar hornikusers\name{annotations_in_spans} \alias{annotations_in_spans} \title{Annotations contained in character spans} \description{ Extract annotations contained in character spans. } \usage{ annotations_in_spans(x, y) } \arguments{ \item{x}{an \code{\link{Annotation}} object.} \item{y}{a \code{\link{Span}} object, or something coercible to this (such as an \code{\link{Annotation}} object).} } \value{ A list with elements the annotations in \code{x} with character spans contained in the respective elements of \code{y}. } \examples{ ## A simple text. s <- String(" First sentence. Second sentence. ") ## ****5****0****5****0****5****0****5** ## Basic sentence and word token annotation for the text. a <- c(Annotation(1 : 2, rep.int("sentence", 2L), c( 3L, 20L), c(17L, 35L)), Annotation(3 : 6, rep.int("word", 4L), c( 3L, 9L, 20L, 27L), c( 7L, 16L, 25L, 34L))) ## Annotation for word tokens according to sentence: annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"]) } NLP/man/utils.Rd0000644000175100001440000000113212313516303013115 0ustar hornikusers\name{utils} \alias{next_id} \alias{single_feature} \title{Annotation Utilities} \description{Utilities for creating annotation objects.} \usage{ next_id(id) single_feature(value, tag) } \arguments{ \item{id}{an integer vector of annotation ids.} \item{value}{an \R object.} \item{tag}{a character string.} } \details{ \code{next_id()} obtains the next \dQuote{available} id based on the given annotation ids (one more than the maximal non-missing id). \code{single_feature()} creates a single feature from the given value and tag (i.e., a named list with the value named by the tag). } NLP/man/Tokenizer.Rd0000644000175100001440000000544413333070646013751 0ustar hornikusers\name{Tokenizer} \alias{Span_Tokenizer} \alias{as.Span_Tokenizer} \alias{is.Span_Tokenizer} \alias{Token_Tokenizer} \alias{as.Token_Tokenizer} \alias{is.Token_Tokenizer} \title{Tokenizer objects} \description{ Create tokenizer objects. } \usage{ Span_Tokenizer(f, meta = list()) as.Span_Tokenizer(x, ...) Token_Tokenizer(f, meta = list()) as.Token_Tokenizer(x, ...) } \arguments{ \item{f}{a tokenizer function taking the string to tokenize as argument, and returning either the tokens (for \code{Token_Tokenizer}) or their spans (for \code{Span_Tokenizer}).} \item{meta}{a named or empty list of tokenizer metadata tag-value pairs.} \item{x}{an \R object.} \item{...}{further arguments passed to or from other methods.} } \details{ Tokenization is the process of breaking a text string up into words, phrases, symbols, or other meaningful elements called tokens. This can be accomplished by returning the sequence of tokens, or the corresponding spans (character start and end positions). We refer to tokenization resources of the respective kinds as \dQuote{token tokenizers} and \dQuote{span tokenizers}. \code{Span_Tokenizer()} and \code{Token_Tokenizer()} return tokenizer objects which are functions with metadata and suitable class information, which in turn can be used for converting between the two kinds using \code{as.Span_Tokenizer()} or \code{as.Token_Tokenizer()}. It is also possible to coerce annotator (pipeline) objects to tokenizer objects, provided that the annotators provide suitable token annotations. By default, word tokens are used; this can be controlled via the \code{type} argument of the coercion methods (e.g., use \code{type = "sentence"} to extract sentence tokens). There are also \code{print()} and \code{format()} methods for tokenizer objects, which use the \code{description} element of the metadata if available. } \seealso{ \code{\link{Regexp_Tokenizer}()} for creating regexp span tokenizers. } \examples{ ## A simple text. s <- String(" First sentence. Second sentence. ") ## ****5****0****5****0****5****0****5** ## Use a pre-built regexp (span) tokenizer: wordpunct_tokenizer wordpunct_tokenizer(s) ## Turn into a token tokenizer: tt <- as.Token_Tokenizer(wordpunct_tokenizer) tt tt(s) ## Of course, in this case we could simply have done s[wordpunct_tokenizer(s)] ## to obtain the tokens from the spans. ## Conversion also works the other way round: package 'tm' provides ## the following token tokenizer function: scan_tokenizer <- function(x) scan(text = as.character(x), what = "character", quote = "", quiet = TRUE) ## Create a token tokenizer from this: tt <- Token_Tokenizer(scan_tokenizer) tt(s) ## Turn into a span tokenizer: st <- as.Span_Tokenizer(tt) st(s) ## Checking tokens from spans: s[st(s)] } NLP/man/String.Rd0000644000175100001440000000440012532125025013224 0ustar hornikusers\name{String} \alias{String} \alias{as.String} \alias{is.String} \title{String objects} \description{ Creation and manipulation of string objects. } \usage{ String(x) as.String(x) is.String(x) } \arguments{ \item{x}{a character vector with the appropriate encoding information for \code{String()}; an arbitrary \R object otherwise. } } \details{ String objects provide character strings encoded in UTF-8 with class \code{"String"}, which currently has a useful \code{[} subscript method: with indices \code{i} and \code{j} of length one, this gives a string object with the substring starting at the position given by \code{i} and ending at the position given by \code{j}; subscripting with a single index which is an object inheriting from class \code{"\link{Span}"} or a list of such objects returns a character vector of substrings with the respective spans, or a list thereof. Additional methods may be added in the future. \code{String()} creates a string object from a given character vector, taking the first element of the vector and converting it to UTF-8 encoding. \code{as.String()} is a generic function to coerce to a string object. The default method calls \code{String()} on the result of converting to character and concatenating into a single string with the elements separated by newlines. \code{is.String()} tests whether an object inherits from class \code{"String"}. } \value{ For \code{String()} and \code{as.String()}, a string object (of class \code{"String"}). For \code{is.String()}, a logical. } \examples{ ## A simple text. s <- String(" First sentence. Second sentence. ") ## ****5****0****5****0****5****0****5** ## Basic sentence and word token annotation for the text. a <- c(Annotation(1 : 2, rep.int("sentence", 2L), c( 3L, 20L), c(17L, 35L)), Annotation(3 : 6, rep.int("word", 4L), c( 3L, 9L, 20L, 27L), c( 7L, 16L, 25L, 34L))) ## All word tokens (by subscripting with an annotation object): s[a[a$type == "word"]] ## Word tokens according to sentence (by subscripting with a list of ## annotation objects): s[annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"])] } NLP/man/language.Rd0000644000175100001440000000635513333070446013562 0ustar hornikusers\name{language} \alias{parse_IETF_language_tag} \title{Parse IETF Language Tag} \description{ Extract language, script, region and variant subtags from IETF language tags. } \usage{parse_IETF_language_tag(x, expand = FALSE)} \arguments{ \item{x}{a character vector with IETF language tags.} \item{expand}{a logical indicating whether to expand subtags into their description(s).} } \details{ Internet Engineering Task Force (IETF) language tags are defined by IETF BCP 47, which is currently composed by the normative RFC 5646 (\url{https://tools.ietf.org/html/rfc5646}) and RFC 4647 (\url{https://tools.ietf.org/html/rfc4646}), along with the normative content of the IANA Language Subtag Registry regulated by these RFCs. These tags are used in a number of modern computing standards. Each language tag is composed of one or more \dQuote{subtags} separated by hyphens. Normal language tags have the following subtags: \itemize{ \item a language subtag (optionally, with language extension subtags), \item an optional script subtag, \item an optional region subtag, \item optional variant subtags, \item optional extension subtags, \item an optional private use subtag. } Language subtags are mainly derived from ISO 639-1 and ISO 639-2, script subtags from ISO 15924, and region subtags from ISO 3166-1 alpha-2 and UN M.49, see package \pkg{ISOcodes} for more information about these standards. Variant subtags are not derived from any standard. The Language Subtag Registry (\url{https://www.iana.org/assignments/language-subtag-registry}), maintained by the Internet Assigned Numbers Authority (IANA), lists the current valid public subtags, as well as the so-called \dQuote{grandfathered} language tags. See \url{https://en.wikipedia.org/wiki/IETF_language_tag} for more information. } \value{ If \code{expand} is false, a list of character vectors of the form \code{"\var{type}=\var{subtag}"}, where \var{type} gives the type of the corresponding subtag (one of \sQuote{Language}, \sQuote{Extlang}, \sQuote{Script}, \sQuote{Region}, \sQuote{Variant}, or \sQuote{Extension}), or \code{"\var{type}=\var{tag}"} with \var{type} either \sQuote{Privateuse} or \sQuote{Grandfathered}. Otherwise, a list of lists of character vectors obtained by replacing the subtags by their corresponding descriptions (which may be multiple) from the IANA registry. Note that no such descriptions for Extension and Privateuse subtags are available in the registry; on the other hand, empty expansions of the other subtags indicate malformed tags (as these subtags must be available in the registry). } \examples{ ## German as used in Switzerland: parse_IETF_language_tag("de-CH") ## Serbian written using Latin script as used in Serbia and Montenegro: parse_IETF_language_tag("sr-Latn-CS") ## Spanish appropriate to the UN Latin American and Caribbean region: parse_IETF_language_tag("es-419") ## All in one: parse_IETF_language_tag(c("de-CH", "sr-Latn-CS", "es-419")) parse_IETF_language_tag(c("de-CH", "sr-Latn-CS", "es-419"), expand = TRUE) ## Two grandfathered tags: parse_IETF_language_tag(c("i-klingon", "zh-min-nan"), expand = TRUE) } \keyword{utilities} NLP/man/generics.Rd0000644000175100001440000000273212314546106013570 0ustar hornikusers\name{generics} \alias{content} \alias{content<-} \alias{meta} \alias{meta<-} \title{Access or Modify Content or Metadata} \description{ Access or modify the content or metadata of \R objects. } \usage{ content(x) content(x) <- value meta(x, tag = NULL, ...) meta(x, tag = NULL, ...) <- value } \arguments{ \item{x}{an \R object.} \item{value}{a suitable \R object.} \item{tag}{a character string or \code{NULL} (default), indicating to return the single metadata value for the given tag, or all metadata tag/value pairs.} \item{...}{arguments to be passed to or from methods.} } \details{ These are generic functions, with no default methods. Often, classed \R objects (e.g., those representing text documents in packages \pkg{NLP} and \pkg{tm}) contain information that can be grouped into \dQuote{content}, metadata and other components, where content can be arbitrary, and metadata are collections of tag/value pairs represented as named or empty lists. The \code{content()} and \code{meta()} getters and setters aim at providing a consistent high-level interface to the respective information (abstracting from how classes internally represent the information). } \value{ Methods for \code{meta()} should return a named or empty list of tag/value pairs if no tag is given (default), or the value for the given tag. } \seealso{ \code{\link{TextDocument}} for basic information on the text document infrastructure employed by package \pkg{NLP}. } NLP/man/TaggedTextDocument.Rd0000644000175100001440000000662313333065422015532 0ustar hornikusers\name{TaggedTextDocument} \alias{TaggedTextDocument} \title{POS-Tagged Word Text Documents} \description{ Create text documents from files containing POS-tagged words. } \usage{ TaggedTextDocument(con, encoding = "unknown", word_tokenizer = whitespace_tokenizer, sent_tokenizer = Regexp_Tokenizer("\n", invert = TRUE), para_tokenizer = blankline_tokenizer, sep = "/", meta = list()) } \arguments{ \item{con}{a connection object or a character string. See \code{\link{readLines}()} for details. } \item{encoding}{encoding to be assumed for input strings. See \code{\link{readLines}()} for details. } \item{word_tokenizer}{a function for obtaining the word token spans.} \item{sent_tokenizer}{a function for obtaining the sentence token spans.} \item{para_tokenizer}{a function for obtaining the paragraph token spans, or \code{NULL} in which case no paragraph tokenization is performed.} \item{sep}{the character string separating the word tokens and their POS tags.} \item{meta}{a named or empty list of document metadata tag-value pairs.} } \details{ \code{TaggedTextDocument()} creates documents representing natural language text as suitable collections of POS-tagged words, based on using \code{\link{readLines}()} to read text lines from connections providing such collections. The text read is split into paragraph, sentence and tagged word tokens using the span tokenizers specified by arguments \code{para_tokenizer}, \code{sent_tokenizer} and \code{word_tokenizer}. By default, paragraphs are assumed to be separated by blank lines, sentences by newlines and tagged word tokens by whitespace. Finally, word tokens and their POS tags are obtained by splitting the tagged word tokens according to \code{sep}. From this, a suitable representation of the provided collection of POS-tagged words is obtained, and returned as a tagged text document object inheriting from classes \code{"TaggedTextDocument"} and \code{"\link{TextDocument}"}. There are methods for generics \code{\link{words}()}, \code{\link{sents}()}, \code{\link{paras}()}, \code{\link{tagged_words}()}, \code{\link{tagged_sents}()}, and \code{\link{tagged_paras}()} (as well as \code{\link{as.character}()}) and class \code{"TaggedTextDocument"}, which should be used to access the text in such text document objects. The methods for generics \code{\link{tagged_words}()}, \code{\link{tagged_sents}()} and \code{\link{tagged_paras}()} provide a mechanism for mapping POS tags via the \code{map} argument, see section \bold{Details} in the help page for \code{\link{tagged_words}()} for more information. The POS tagset used will be inferred from the \code{POS_tagset} metadata element of the CoNLL-style text document. } \value{ A tagged text document object inheriting from \code{"TaggedTextDocument"} and \code{"\link{TextDocument}"}. } \seealso{ \url{http://nltk.github.com/nltk_data/packages/corpora/brown.zip} which provides the W. N. Francis and H. Kucera Brown tagged word corpus as an archive of files which can be read in using \code{TaggedTextDocument()}. Package \pkg{tm.corpus.Brown} available from the repository at \url{https://datacube.wu.ac.at} conveniently provides this corpus as a \pkg{tm} \link[tm:VCorpus]{VCorpus} of tagged text documents. } NLP/man/Tagged_Token.Rd0000644000175100001440000000433712510736106014326 0ustar hornikusers\name{Tagged_Token} \alias{Tagged_Token} \alias{as.Tagged_Token} \alias{is.Tagged_Token} \alias{[.Tagged_Token} %% \alias{[<-.Tagged_Token} \alias{[[.Tagged_Token} %% \alias{[[<-.Tagged_Token} \alias{$<-.Tagged_Token} \alias{as.data.frame.Tagged_Token} \alias{as.list.Tagged_Token} \alias{c.Tagged_Token} \alias{duplicated.Tagged_Token} \alias{format.Tagged_Token} \alias{length.Tagged_Token} \alias{names.Tagged_Token} \alias{print.Tagged_Token} \alias{unique.Tagged_Token} \title{Tagged_Token objects} \description{ Creation and manipulation of tagged token objects. } \usage{ Tagged_Token(token, tag) as.Tagged_Token(x) is.Tagged_Token(x) } \arguments{ \item{token, tag}{character vectors giving tokens and the corresponding tags.} \item{x}{an \R object.} } \details{ A tagged token is a pair with \dQuote{slots} \sQuote{token} and \sQuote{tag}, giving the token and the corresponding tag. Tagged token objects provide sequences (allowing positional access) of single tagged tokens. They have class \code{"Tagged_Token"}. Subscripting tagged token objects via \code{[} extracts subsets of tagged tokens; subscripting via \code{$} extracts character vectors with the sequence of values of the named slot. There are several additional methods for class \code{"Tagged_Token"}: \code{print()} and \code{format()} (which concatenate tokens and tags separated by \samp{/}); \code{c()} combines tagged token objects (or objects coercible to these using \code{as.Tagged_Token()}), and \code{as.list()} and \code{as.data.frame()} coerce, respectively, to lists (of single tagged token objects) and data frames (with tagged tokens and slots corresponding to rows and columns). \code{Tagged_Token()} creates tagged token objects from the given sequences of tokens and tags, which must have the same length. \code{as.Tagged_Token()} coerces to tagged token objects, with a method for \code{\link{TextDocument}} objects using \code{\link{tagged_words}()}. \code{is.Tagged_Token()} tests whether an object inherits from class \code{"Tagged_Token"}. } \value{ For \code{Tagged_Token()} and \code{as.Tagged_Token()}, a tagged token object (of class \code{"Tagged_Token"}). For \code{is.Tagged_Token()}, a logical. } NLP/man/ngrams.Rd0000644000175100001440000000113513333064622013254 0ustar hornikusers\name{ngrams} \alias{ngrams} \title{Compute N-Grams} \description{ Compute the \eqn{n}-grams (contiguous sub-sequences of length \eqn{n}) of a given sequence. } \arguments{ \item{x}{a sequence (vector).} \item{n}{a positive integer giving the length of contiguous sub-sequences to be computed.} } \value{ a list with the computed sub-sequences. } \examples{ s <- "The quick brown fox jumps over the lazy dog" ## Split into words: w <- strsplit(s, " ", fixed = TRUE)[[1L]] ## Word tri-grams: ngrams(w, 3L) ## Word tri-grams pasted together: vapply(ngrams(w, 3L), paste, "", collapse = " ") } NLP/man/viewers.Rd0000644000175100001440000000622713337765004013466 0ustar hornikusers\name{viewers} \alias{sents} \alias{words} \alias{paras} \alias{tagged_sents} \alias{tagged_paras} \alias{tagged_words} \alias{chunked_sents} \alias{parsed_sents} \alias{parsed_paras} \title{Text Document Viewers} \description{ Provide suitable \dQuote{views} of the text contained in text documents. } \usage{ words(x, ...) sents(x, ...) paras(x, ...) tagged_words(x, ...) tagged_sents(x, ...) tagged_paras(x, ...) chunked_sents(x, ...) parsed_sents(x, ...) parsed_paras(x, ...) } \arguments{ \item{x}{a text document object.} \item{...}{further arguments to be passed to or from methods.} } \details{ Methods for extracting POS tagged word tokens (i.e., for generics \code{tagged_words()}, \code{tagged_sents()} and \code{tagged_paras()}) can optionally provide a mechanism for mapping the POS tags via a \code{map} argument. This can give a function, a named character vector (with names and elements the tags to map from and to, respectively), or a named list of such named character vectors, with names corresponding to POS tagsets (see \code{\link{Universal_POS_tags_map}} for an example). If a list, the map used will be the element with name matching the POS tagset used (this information is typically determined from the text document metadata; see the the help pages for text document extension classes implementing this mechanism for details). In addition to methods for the text document classes provided by package \pkg{NLP} itself, (see \link{TextDocument}), package \pkg{NLP} also provides word tokens and POS tagged word tokens for the results of \code{\link[udpipe:udpipe_annotate]{udpipe_annotate}()} from package \CRANpkg{udpipe}, \code{\link[spacyr:spacy_parse]{spacy_parse}()} from package \CRANpkg{spacyr}, and \code{\link[cleanNLP:cnlp_annotate]{cnlp_annotate}()} from package \CRANpkg{cleanNLP}. } \value{ For \code{words()}, a character vector with the word tokens in the document. For \code{sents()}, a list of character vectors with the word tokens in the sentences. For \code{paras()}, a list of lists of character vectors with the word tokens in the sentences, grouped according to the paragraphs. For \code{tagged_words()}, a character vector with the POS tagged word tokens in the document (i.e., the word tokens and their POS tags, separated by \samp{/}). For \code{tagged_sents()}, a list of character vectors with the POS tagged word tokens in the sentences. For \code{tagged_paras()}, a list of lists of character vectors with the POS tagged word tokens in the sentences, grouped according to the paragraphs. For \code{chunked_sents()}, a list of (flat) \code{\link{Tree}} objects giving the chunk trees for the sentences in the document. For \code{parsed_sents()}, a list of \code{\link{Tree}} objects giving the parse trees for the sentences in the document. For \code{parsed_paras()}, a list of lists of \code{\link{Tree}} objects giving the parse trees for the sentences in the document, grouped according to the paragraphs in the document. } \seealso{ \code{\link{TextDocument}} for basic information on the text document infrastructure employed by package \pkg{NLP}. } NLP/man/datetime.Rd0000644000175100001440000000366413333066244013574 0ustar hornikusers\name{datetime} \alias{parse_ISO_8601_datetime} \title{Parse ISO 8601 Date/Time Strings} \description{ Extract date/time components from strings following one of the six formats specified in the NOTE-datetime ISO 8601 profile (\url{https://www.w3.org/TR/NOTE-datetime}). } \arguments{ \item{x}{a character vector.} } \details{ For character strings in one of the formats in the profile, the corresponding date/time components are extracted, with seconds and decimal fractions of seconds combined. Other (malformed) strings are warned about. The extracted components for each string are gathered into a named list with elements of the appropriate type (integer for year to min; double for sec; character for the time zone designator). The object returned is a (suitably classed) list of such named lists. This internal representation may change in future versions. One can subscript such ISO 8601 date/time objects using \code{[} and extract components using \code{$} (where missing components will result in \code{NA}s), and convert them to the standard R date/time classes using \code{\link{as.Date}()}, \code{\link{as.POSIXct}()} and \code{\link{as.POSIXlt}()} (incomplete elements will convert to suitably missing elements). In addition, there are \code{print()} and \code{as.data.frame()} methods for such objects. } \value{ An object inheriting from class \code{"ISO_8601_datetime"} with the extracted date/time components. } \examples{ ## Use the examples from , plus one ## in UTC. x <- c("1997", "1997-07", "1997-07-16", "1997-07-16T19:20+01:00", "1997-07-16T19:20:30+01:00", "1997-07-16T19:20:30.45+01:00", "1997-07-16T19:20:30.45Z") y <- parse_ISO_8601_datetime(x) y ## Conversions: note that "incomplete" elements are converted to ## "missing". as.Date(y) as.POSIXlt(y) ## Subscripting and extracting components: head(y, 3) y$mon } NLP/man/CoNLLTextDocument.Rd0000644000175100001440000000735713333615255015260 0ustar hornikusers\name{CoNLLTextDocument} \alias{CoNLLTextDocument} \title{CoNLL-Style Text Documents} \description{ Create text documents from CoNLL-style files. } \usage{ CoNLLTextDocument(con, encoding = "unknown", format = "conll00", meta = list()) } \arguments{ \item{con}{a connection object or a character string. See \code{\link{scan}()} for details. } \item{encoding}{encoding to be assumed for input strings. See \code{\link{scan}()} for details. } \item{format}{a character vector specifying the format. See \bold{Details}. } \item{meta}{a named or empty list of document metadata tag-value pairs.} } \details{ CoNLL-style files use an extended tabular format where empty lines separate sentences, and non-empty lines consist of whitespace separated columns giving the word tokens and annotations for these. Such formats were popularized through their use for the shared tasks of CoNLL (Conference on Natural Language Learning), the yearly meeting of the Special Interest Group on Natural Language Learning of the Association for Computational Linguistics (see \url{http://www.signll.org/conll/} for more information about CoNLL). The precise format can vary according to corpus, and must be specified via argument \code{format}, as either a character string giving a pre-defined format, or otherwise a character vector with elements giving the names of the \sQuote{fields} (columns), and names used to give the field \sQuote{types}, with \sQuote{WORD}, \sQuote{POS} and \sQuote{CHUNK} to be used for, respectively, word tokens, POS tags, and chunk tags. For example, \preformatted{ c(WORD = "WORD", POS = "POS", CHUNK = "CHUNK")} would be a format specification appropriate for the CoNLL-2000 chunking task, as also available as the pre-defined \code{"conll00"}, which serves as default format for reasons of back-compatibility. Other pre-defined formats are \code{"conll01"} (for the CoNLL-2001 clause identification task), \code{"conll02"} (for the CoNLL-2002 language-independent named entity recognition task), \code{"conllx"} (for the CoNLL-X format used in at least the CoNLL-2006 and CoNLL-2007 multilingual dependency parsing tasks), and \code{"conll09"} (for the CoNLL-2009 shared task on syntactic and semantic dependencies in multiple languages). The lines are read from the given connection and split into fields using \code{\link{scan}()}. From this, a suitable representation of the provided information is obtained, and returned as a CoNLL text document object inheriting from classes \code{"CoNLLTextDocument"} and \code{"\link{TextDocument}"}. There are methods for class \code{"CoNLLTextDocument"} and generics \code{\link{words}()}, \code{\link{sents}()}, \code{\link{tagged_words}()}, \code{\link{tagged_sents}()}, and \code{\link{chunked_sents}()} (as well as \code{\link{as.character}()}), which should be used to access the text in such text document objects. The methods for generics \code{\link{tagged_words}()} and \code{\link{tagged_sents}()} provide a mechanism for mapping POS tags via the \code{map} argument, see section \bold{Details} in the help page for \code{\link{tagged_words}()} for more information. The POS tagset used will be inferred from the \code{POS_tagset} metadata element of the CoNLL-style text document. } \value{ An object inheriting from \code{"CoNLLTextDocument"} and \code{"\link{TextDocument}"}. } \seealso{ \code{\link{TextDocument}} for basic information on the text document infrastructure employed by package \pkg{NLP}. \url{https://www.clips.uantwerpen.be/conll2000/chunking/} for the CoNLL-2000 chunking task, and training and test data sets which can be read in using \code{CoNLLTextDocument()}. } NLP/man/Annotation.Rd0000644000175100001440000001513013357140760014103 0ustar hornikusers\name{Annotation} \alias{Annotation} \alias{as.Annotation} \alias{as.Annotation.Span} \alias{is.Annotation} \alias{[.Annotation} %% \alias{[<-.Annotation} \alias{[[.Annotation} %% \alias{[[<-.Annotation} \alias{$<-.Annotation} \alias{as.data.frame.Annotation} \alias{as.list.Annotation} \alias{c.Annotation} \alias{duplicated.Annotation} \alias{format.Annotation} \alias{length.Annotation} \alias{merge.Annotation} \alias{meta.Annotation} \alias{meta<-.Annotation} \alias{names.Annotation} \alias{print.Annotation} \alias{subset.Annotation} \alias{unique.Annotation} \title{Annotation objects} \description{ Creation and manipulation of annotation objects. } \usage{ Annotation(id = NULL, type = NULL, start, end, features = NULL, meta = list()) as.Annotation(x, ...) \method{as.Annotation}{Span}(x, id = NULL, type = NULL, ...) is.Annotation(x) } \arguments{ \item{id}{an integer vector giving the annotation ids, or \code{NULL} (default) resulting in missing ids.} \item{type}{a character vector giving the annotation types, or \code{NULL} (default) resulting in missing types.} \item{start, end}{integer vectors giving the start and end positions of the character spans the annotations refer to.} \item{features}{a list of (named or empty) feature lists, or \code{NULL} (default), resulting in empty feature lists.} \item{meta}{a named or empty list of annotation metadata tag-value pairs.} \item{x}{an \R object (an object of class \code{"\link{Span}"} for the coercion methods for such objects).} \item{...}{further arguments passed to or from other methods.} } \details{ A single annotation (of natural language text) is a quintuple with \dQuote{slots} \sQuote{id}, \sQuote{type}, \sQuote{start}, \sQuote{end}, and \sQuote{features}. These give, respectively, id and type, the character span the annotation refers to, and a collection of annotation features (tag/value pairs). Annotation objects provide sequences (allowing positional access) of single annotations, together with metadata about these. They have class \code{"Annotation"} and, as they contain character spans, also inherit from class \code{"\link{Span}"}. Span objects can be coerced to annotation objects via \code{as.Annotation()} which allows to specify ids and types (using the default values sets these to missing), and annotation objects can be coerced to span objects using \code{\link{as.Span}()}. The features of a single annotation are represented as named or empty lists. Subscripting annotation objects via \code{[} extracts subsets of annotations; subscripting via \code{$} extracts the sequence of values of the named slot, i.e., an integer vector for \sQuote{id}, \sQuote{start}, and \sQuote{end}, a character vector for \sQuote{type}, and a list of named or empty lists for \sQuote{features}. There are several additional methods for class \code{"Annotation"}: \code{print()} and \code{format()} (which both have a \code{values} argument which if \code{FALSE} suppresses indicating the feature map values); \code{c()} combines annotations (or objects coercible to these using \code{as.Annotation()}); \code{merge()} merges annotations by combining the feature lists of annotations with otherwise identical slots; \code{subset()} allows subsetting by expressions involving the slot names; and \code{as.list()} and \code{as.data.frame()} coerce, respectively, to lists (of single annotation objects) and data frames (with annotations and slots corresponding to rows and columns). \code{Annotation()} creates annotation objects from the given sequences of slot values: those not \code{NULL} must all have the same length (the number of annotations in the object). \code{as.Annotation()} coerces to annotation objects, with a method for span objects. \code{is.Annotation()} tests whether an object inherits from class \code{"Annotation"}. } \value{ For \code{Annotation()} and \code{as.Annotation()}, an annotation object (of class \code{"Annotation"} also inheriting from class \code{"Span"}). For \code{is.Annotation()}, a logical. } \examples{ ## A simple text. s <- String(" First sentence. Second sentence. ") ## ****5****0****5****0****5****0****5** ## Basic sentence and word token annotations for the text. a1s <- Annotation(1 : 2, rep.int("sentence", 2L), c( 3L, 20L), c(17L, 35L)) a1w <- Annotation(3 : 6, rep.int("word", 4L), c( 3L, 9L, 20L, 27L), c( 7L, 16L, 25L, 34L)) ## Use c() to combine these annotations: a1 <- c(a1s, a1w) a1 ## Subscripting via '[': a1[3 : 4] ## Subscripting via '$': a1$type ## Subsetting according to slot values, directly: a1[a1$type == "word"] ## or using subset(): subset(a1, type == "word") ## We can subscript string objects by annotation objects to extract the ## annotated substrings: s[subset(a1, type == "word")] ## We can also subscript by lists of annotation objects: s[annotations_in_spans(subset(a1, type == "word"), subset(a1, type == "sentence"))] ## Suppose we want to add the sentence constituents (the ids of the ## words in the respective sentences) to the features of the sentence ## annotations. The basic computation is lapply(annotations_in_spans(a1[a1$type == "word"], a1[a1$type == "sentence"]), function(a) a$id) ## For annotations, we need lists of feature lists: features <- lapply(annotations_in_spans(a1[a1$type == "word"], a1[a1$type == "sentence"]), function(e) list(constituents = e$id)) ## Could add these directly: a2 <- a1 a2$features[a2$type == "sentence"] <- features a2 ## Note how the print() method summarizes the features. ## We could also write a sentence constituent annotator ## (note that annotators should always have formals 's' and 'a', even ## though for computing the sentence constituents s is not needed): sent_constituent_annotator <- Annotator(function(s, a) { i <- which(a$type == "sentence") features <- lapply(annotations_in_spans(a[a$type == "word"], a[i]), function(e) list(constituents = e$id)) Annotation(a$id[i], a$type[i], a$start[i], a$end[i], features) }) sent_constituent_annotator(s, a1) ## Can use merge() to merge the annotations: a2 <- merge(a1, sent_constituent_annotator(s, a1)) a2 ## Equivalently, could have used a2 <- annotate(s, sent_constituent_annotator, a1) a2 ## which merges automatically. } NLP/man/Span.Rd0000644000175100001440000000450012502573125012665 0ustar hornikusers\name{Span} \alias{Span} \alias{as.Span} \alias{is.Span} \alias{[.Span} %% \alias{[<-.Span} \alias{[[.Span} %% \alias{[[<-.Span} \alias{$<-.Span} \alias{Ops.Span} \alias{as.data.frame.Span} \alias{as.list.Span} \alias{c.Span} \alias{duplicated.Span} \alias{format.Span} \alias{length.Span} \alias{names.Span} \alias{print.Span} \alias{unique.Span} \title{Span objects} \description{ Creation and manipulation of span objects. } \usage{ Span(start, end) as.Span(x) is.Span(x) } \arguments{ \item{start, end}{integer vectors giving the start and end positions of the spans.} \item{x}{an \R object.} } \details{ A single span is a pair with \dQuote{slots} \sQuote{start} and \sQuote{end}, giving the start and end positions of the span. Span objects provide sequences (allowing positional access) of single spans. They have class \code{"Span"}. Span objects can be coerced to annotation objects via \code{\link{as.Annotation}()} (which of course is only appropriate provided that the spans are character spans of the natural language text being annotated), and annotation objects can be coerced to span objects via \code{as.Span()} (giving the character spans of the annotations). Subscripting span objects via \code{[} extracts subsets of spans; subscripting via \code{$} extracts integer vectors with the sequence of values of the named slot. There are several additional methods for class \code{"Span"}: \code{print()} and \code{format()}; \code{c()} combines spans (or objects coercible to these using \code{as.Span()}), and \code{as.list()} and \code{as.data.frame()} coerce, respectively, to lists (of single span objects) and data frames (with spans and slots corresponding to rows and columns). Finally, one can add a scalar and a span object (resulting in shifting the start and end positions by the scalar). \code{Span()} creates span objects from the given sequences of start and end positions, which must have the same length. \code{as.Span()} coerces to span objects, with a method for annotation objects. \code{is.Span()} tests whether an object inherits from class \code{"Span"} (and hence returns \code{TRUE} for both span and annotation objects). } \value{ For \code{Span()} and \code{as.Span()}, a span object (of class \code{"Span"}). For \code{is.Span()}, a logical. } NLP/man/TextDocument.Rd0000644000175100001440000000302313144533560014410 0ustar hornikusers\name{TextDocument} \alias{TextDocument} \title{Text Documents} \description{ Representing and computing on text documents. } \details{ \emph{Text documents} are documents containing (natural language) text. In packages which employ the infrastructure provided by package \pkg{NLP}, such documents are represented via the virtual S3 class \code{"TextDocument"}: such packages then provide S3 text document classes extending the virtual base class (such as the \code{\link{AnnotatedPlainTextDocument}} objects provided by package \pkg{NLP} itself). All extension classes must provide an \code{\link{as.character}()} method which extracts the natural language text in documents of the respective classes in a \dQuote{suitable} (not necessarily structured) form, as well as \code{\link{content}()} and \code{\link{meta}()} methods for accessing the (possibly raw) document content and metadata. In addition, the infrastructure features the generic functions \code{\link{words}()}, \code{\link{sents}()}, etc., for which extension classes can provide methods giving a structured view of the text contained in documents of these classes (returning, e.g., a character vector with the word tokens in these documents, and a list of such character vectors). } \seealso{ \code{\link{AnnotatedPlainTextDocument}}, \code{\link{CoNLLTextDocument}}, \code{\link{CoNLLUTextDocument}}, \code{\link{TaggedTextDocument}}, and \code{\link{WordListDocument}} for the text document classes provided by package \pkg{NLP}. } NLP/man/tagsets.Rd0000644000175100001440000000363113333070602013435 0ustar hornikusers\name{tagsets} \alias{Penn_Treebank_POS_tags} \alias{Brown_POS_tags} \alias{Universal_POS_tags} \alias{Universal_POS_tags_map} \title{NLP Tag Sets} \description{ Tag sets frequently used in Natural Language Processing. } \usage{ Penn_Treebank_POS_tags Brown_POS_tags Universal_POS_tags Universal_POS_tags_map } \details{ \code{Penn_Treebank_POS_tags} and \code{Brown_POS_tags} provide, respectively, the Penn Treebank POS tags (\url{https://catalog.ldc.upenn.edu/docs/LDC95T7/cl93.html}, Table 2) and the POS tags used for the Brown corpus (\url{http://www.hit.uib.no/icame/brown/bcm.html}), both as data frames with the following variables: \describe{ \item{entry}{a character vector with the POS tags} \item{description}{a character vector with short descriptions of the tags} \item{examples}{a character vector with examples for the tags} } \code{Universal_POS_tags} provides the universal POS tagset introduced by Slav Petrov, Dipanjan Das, and Ryan McDonald (\url{https://arxiv.org/abs/1104.2086}), as a data frame with character variables \code{entry} and \code{description}. \code{Universal_POS_tags_map} is a named list of mappings from language and treebank specific POS tagsets to the universal POS tags, with elements named \samp{en-ptb} and \samp{en-brown} giving the mappings, respectively, for the Penn Treebank and Brown POS tags. } \source{ \url{https://catalog.ldc.upenn.edu/docs/LDC95T7/cl93.html}, \url{http://www.hit.uib.no/icame/brown/bcm.html}, \url{https://code.google.com/p/universal-pos-tags/}. } \examples{ ## Penn Treebank POS tags dim(Penn_Treebank_POS_tags) ## Inspect first 20 entries: write.dcf(head(Penn_Treebank_POS_tags, 20L)) ## Brown POS tags dim(Brown_POS_tags) ## Inspect first 20 entries: write.dcf(head(Brown_POS_tags, 20L)) ## Universal POS tags Universal_POS_tags ## Available mappings to universal POS tags names(Universal_POS_tags_map) } NLP/man/Annotator.Rd0000644000175100001440000000634013112000174013720 0ustar hornikusers\name{Annotator} \alias{Annotator} \alias{Annotator_Pipeline} \alias{as.Annotator_Pipeline} \title{Annotator (pipeline) objects} \description{ Create annotator (pipeline) objects. } \usage{ Annotator(f, meta = list(), classes = NULL) Annotator_Pipeline(..., meta = list()) as.Annotator_Pipeline(x) } \arguments{ \item{f}{an annotator function, which must have formals \code{s} and \code{a} giving, respectively, the string with the natural language text to annotate and an annotation object to start from, and return an annotation object with the computed annotations.} \item{meta}{an empty or named list of annotator (pipeline) metadata tag-value pairs.} \item{classes}{a character vector or \code{NULL} (default) giving classes to be used for the created annotator object in addition to \code{"Annotator"}.} \item{...}{annotator objects.} \item{x}{an \R object.} } \details{ \code{Annotator()} checks that the given annotator function has the appropriate formals, and returns an annotator object which inherits from the given classes and \code{"Annotator"}. There are \code{print()} and \code{format()} methods for such objects, which use the \code{description} element of the metadata if available. \code{Annotator_Pipeline()} creates an annotator pipeline object from the given annotator objects. Such pipeline objects can be used by \code{\link{annotate}()} for successively computing and merging annotations, and can also be obtained by coercion with \code{as.Annotator_Pipeline()}, which currently handles annotator objects and lists of such (and of course, annotator pipeline objects). } \value{ For \code{Annotator()}, an annotator object inheriting from the given classes and class \code{"Annotator"}. For \code{Annotator_Pipeline()} and \code{as.Annotator_Pipeline()}, an annotator pipeline object inheriting from class \code{"Annotator_Pipeline"}. } \seealso{ \link{Simple annotator generators} for creating \dQuote{simple} annotator objects based on function performing simple basic NLP tasks. Package \pkg{StanfordCoreNLP} available from the repository at \url{https://datacube.wu.ac.at} which provides generators for annotator pipelines based on the Stanford CoreNLP tools. } \examples{ ## Use blankline_tokenizer() for a simple paragraph token annotator: para_token_annotator <- Annotator(function(s, a = Annotation()) { spans <- blankline_tokenizer(s) n <- length(spans) ## Need n consecutive ids, starting with the next "free" ## one: from <- next_id(a$id) Annotation(seq(from = from, length.out = n), rep.int("paragraph", n), spans$start, spans$end) }, list(description = "A paragraph token annotator based on blankline_tokenizer().")) para_token_annotator ## Alternatively, use Simple_Para_Token_Annotator(). ## A simple text with two paragraphs: s <- String(paste(" First sentence. Second sentence. ", " Second paragraph. ", sep = "\n\n")) a <- annotate(s, para_token_annotator) ## Annotations for paragraph tokens. a ## Extract paragraph tokens. s[a] }