R错误中的“错误点”[[1L]] [[1L]]:'闭包'类型的对象不是子集“

时间:2017-06-06 15:50:34

标签: r mapply

我有这段代码:mapply(annotate, maxs, s, ann) 其中annotate是一个函数,它接受一个注释器对象(maxs),一个字符串和一个带注释的对象(ann)。 s是一个字符串列表和ann一个等长的带注释对象列表。

这是我得到的错误:

  

点[[1L]] [[1L]]出错:'闭合'类型的对象不是   subsettable

信息&代码:

 s <- c("hello world", "hello world")                                                                             

require(openNLP)
    require(NLP)
    require(openNLPmodels.en)
    require(tm) #optional
    require(hash) #optional
    require(openNLPdata) #optional  


sent_token_annotator <- Maxent_Sent_Token_Annotator()
    word_token_annotator <- Maxent_Word_Token_Annotator()
    pos_tag_annotator <- Maxent_POS_Tag_Annotator()

    ann <- sapply(s, annotate, list(sent_token_annotator,
                                   word_token_annotator,
                                   pos_tag_annotator))

maxs<-Maxent_Chunk_Annotator(probs = FALSE)

> maxs; str(maxs); s; str(s); ann; str(ann);
An annotator inheriting from classes
  Simple_Chunk_Annotator Annotator
with description
  Computes chunk annotations using the Apache OpenNLP Maxent chunker employing the default model for language 'en'.
function (s, a)  
 - attr(*, "meta")=List of 1
  ..$ description: chr "Computes chunk annotations using the Apache OpenNLP Maxent chunker employing the default model for language 'en'."
 - attr(*, "class")= chr [1:2] "Simple_Chunk_Annotator" "Annotator"
[1] "hello world" "hello world"
 chr [1:2] "hello world" "hello world"
 id type     start end features
  1 sentence     1  23 constituents=<<integer,4>>
  2 word         1   5 POS=UH
  3 word         7  11 POS=NN
  4 word        13  17 POS=UH
  5 word        19  23 POS=NN
List of 5
 $ :Classes 'Annotation', 'Span'  hidden list of 5
  ..$ id      : int 1
  ..$ type    : chr "sentence"
  ..$ start   : int 1
  ..$ end     : int 23
  ..$ features:List of 1
  .. ..$ :List of 1
  .. .. ..$ constituents: int [1:4] 2 3 4 5
  ..- attr(*, "meta")=List of 2
  .. ..$ POS_tagset    : chr "en-ptb"
  .. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
 $ :Classes 'Annotation', 'Span'  hidden list of 5
  ..$ id      : int 2
  ..$ type    : chr "word"
  ..$ start   : int 1
  ..$ end     : int 5
  ..$ features:List of 1
  .. ..$ :List of 1
  .. .. ..$ POS: chr "UH"
  ..- attr(*, "meta")=List of 2
  .. ..$ POS_tagset    : chr "en-ptb"
  .. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
 $ :Classes 'Annotation', 'Span'  hidden list of 5
  ..$ id      : int 3
  ..$ type    : chr "word"
  ..$ start   : int 7
  ..$ end     : int 11
  ..$ features:List of 1
  .. ..$ :List of 1
  .. .. ..$ POS: chr "NN"
  ..- attr(*, "meta")=List of 2
  .. ..$ POS_tagset    : chr "en-ptb"
  .. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
 $ :Classes 'Annotation', 'Span'  hidden list of 5
  ..$ id      : int 4
  ..$ type    : chr "word"
  ..$ start   : int 13
  ..$ end     : int 17
  ..$ features:List of 1
  .. ..$ :List of 1
  .. .. ..$ POS: chr "UH"
  ..- attr(*, "meta")=List of 2
  .. ..$ POS_tagset    : chr "en-ptb"
  .. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
 $ :Classes 'Annotation', 'Span'  hidden list of 5
  ..$ id      : int 5
  ..$ type    : chr "word"
  ..$ start   : int 19
  ..$ end     : int 23
  ..$ features:List of 1
  .. ..$ :List of 1
  .. .. ..$ POS: chr "NN"
  ..- attr(*, "meta")=List of 2
  .. ..$ POS_tagset    : chr "en-ptb"
  .. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
 - attr(*, "class")= chr [1:2] "Annotation" "Span"
 - attr(*, "meta")=List of 2
  ..$ POS_tagset    : chr "en-ptb"
  ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"

`

非常感谢您的帮助! TY

0 个答案:

没有答案