File: viewers.R

package info (click to toggle)
r-cran-nlp 0.3-2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 456 kB
  • sloc: makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
words <-
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")

otoks <-
function(x, ...)
    UseMethod("otoks")

chunk_tree_from_chunk_info <-
function(words, ptags, ctags)
{
    ind <- grepl("^[BO]", ctags)
    ## <FIXME>
    ## Should this also use Tagged_Token()?
    chunks <- split(sprintf("%s/%s", words, ptags), cumsum(ind))
    ## </FIXME>
    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]
}