Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中向corelabel强制转换字符串?_Java_Casting_Stanford Nlp - Fatal编程技术网

如何在java中向corelabel强制转换字符串?

如何在java中向corelabel强制转换字符串?,java,casting,stanford-nlp,Java,Casting,Stanford Nlp,我正在使用斯坦福解析器。我得到一个错误: 无法将字符串解析为Corelabel 下面是一些代码: List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); for(CoreMap sentence: sentences) { CoreLabel temp=sentence.toString().replace(clust2, clust); sentenc

我正在使用斯坦福解析器。我得到一个错误:

无法将字符串解析为Corelabel

下面是一些代码:

List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for(CoreMap sentence: sentences) 
{
    CoreLabel temp=sentence.toString().replace(clust2, clust);
    sentences.set(m.sentNum-1,temp);              
}     

您不能强制转换,但可能可以转换,但这取决于CoreLabel是什么。在某些情况下,可能是CoreLabel CoreLabel=新CoreLabel字符串


您可能无法转换。但是此代码将适用于u

以下函数存在于您可以使用的CoreLabel.java类下

/** This is provided as a simple way to make a CoreLabel for a word from a String.
   *  It's often useful in fixup or test code. It sets all three of the Text, OriginalText,
   *  and Value annotations to the given value.
   *
   *  @param word The word string to make a CoreLabel for
   *  @return A CoreLabel for this word string
   */
  public static CoreLabel wordFromString(String word) {
    CoreLabel cl = new CoreLabel();
    cl.setWord(word);
    cl.setOriginalText(word);
    cl.setValue(word);
    return cl;
  }
/** This is provided as a simple way to make a CoreLabel for a word from a String.
   *  It's often useful in fixup or test code. It sets all three of the Text, OriginalText,
   *  and Value annotations to the given value.
   *
   *  @param word The word string to make a CoreLabel for
   *  @return A CoreLabel for this word string
   */
  public static CoreLabel wordFromString(String word) {
    CoreLabel cl = new CoreLabel();
    cl.setWord(word);
    cl.setOriginalText(word);
    cl.setValue(word);
    return cl;
  }